I’m trying to write a utility which will allow me to quickly switch styles as I generate multiple plots via multiple TCanvas objects generated in my root macro. the problem is that the font size is not correct when I try and put the plot in .png form into a word document. What I want to do is change the size of the font to suit the size of the graph .png file so when I insert it into a word document the axis labels and titles are legible. My problem is that if I change gstyle settings between drawing on canvases, the latest gstyle carries over to the previous TCanvas object. This is very poorly defined.
Here’s my code.
// Size comes in integer units of 1, 2, 3
// where 1 is the size for a full width plot
// 2 is the size for two size by side plots
// 3 is the size for three side by side plots
void SetStyleSize(int Size)
{
int SizeIdx;
double FontSizeLUT[3] = {0.02,0.07,0.1};
double LeftMarginLUT[3] = {0.1,0.175,0.25};
double BottomMarginLUT[3] = {0.1,0.15,0.225};
double TopMarginLUT[3] = {0.1,0.1,0.125};
double RightMarginLUT[3] = {0.1,0.1,0.1};
double TitleYOffsetLUT[3] = {1.,1.,1.};
int NDivisionsLUT[3] = {510,510,505};
if ((Size<1)||(Size>3)) {
cout << "Size " << Size << " not implemented, setting size to 1";
Size=1;
}
SizeIdx = Size-1;
gStyle->SetTextSize(FontSizeLUT[SizeIdx]);
gStyle->SetTitleSize(FontSizeLUT[SizeIdx],"xyz");
gStyle->SetTitleSize(FontSizeLUT[SizeIdx],"a");
gStyle->SetLabelSize(FontSizeLUT[SizeIdx],"xyz");
gStyle->SetLegendTextSize(FontSizeLUT[SizeIdx]);
gStyle->SetTitleOffset(TitleYOffsetLUT[SizeIdx],"y");
gStyle->SetNdivisions(NDivisionsLUT[SizeIdx],"xyz");
gStyle->SetPadLeftMargin(LeftMarginLUT[SizeIdx]);
gStyle->SetPadRightMargin(RightMarginLUT[SizeIdx]);
gStyle->SetPadBottomMargin(BottomMarginLUT[SizeIdx]);
gStyle->SetPadTopMargin(TopMarginLUT[SizeIdx]);
}
So the idea is as follows, I call my SetStyleSize(1) function and then I create a TCanvas object and draw my graph, the fonts and styles are just what I wanted. If I then call SetStyleSize(2), then create a new TCanvas, what I draw in the new TCanvas will have the proper font size as I’ve defined using SetStyleSize(2). the problem is that the first graph in the first TCanvas object now has the new size. I want to preserve the font sizes and styles in the first TCanvas object.
Does this make any sense? I hope so. Anyway, any help in this is greatly appreciated.