Save plotting style in .C macro

Hi!

Is it possible to save the current gStyle to the .C macro that gets saved when printing a TCanvas in the
my_canvas->Print("MyCanvas.C");
fashion?

Thanks a lot,
Alex

Iā€™m not sure you can get the TCanvas and TStyle objects to write to the same ā€œ.Cā€ file (probably using bash afterwards), but you can do so separately as you show for the canvas, and for gStyle also:

#include <TROOT.h>
#include <TStyle.h>
gStyle->SaveSource("MyStyle.C")

Cheers,
Etienne

1 Like

In principle the MyCanvas.C macro will reflect exactly what you see on screen and therefore all the settings defined by the current style and used by this macro will be also saved in MyCanvas.C. But if, for some reason, you need the whole TStyle in a separated file the suggestion done by @EtienneDreyer is valid. You can then executed MyStyle.C from any macro.

I found exactly that not to be the case. I saved a plot as a .C macro to have the opportunity to redraw quickly and maybe change a font size etc standalone if needed. But I found that the redrawn plot I got from executing the macro does not look like the original one, I added the gStyle by hand later (including the original macro I used to set the style) which fixed it. I also had to add manually SetNColumns()as well as the SetMargin() to the TLegend that I used in the original plot which did not get saved in the printed .C macro.

The root version is

ROOT Version: 6.16/00
Built for linuxx8664gcc on Jan 23 2019, 09:06:13
From tags/v6-16-00@v6-16-00

maybe that has been fixed in a newer one?

Best,
Alex

May be ā€¦ we are at 6.22 now.
post the macro having this problem and we can have a look.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.