gStyle and style of objects from file

Dear Rooters,

I have the following problem:

I have a file with TCanvases in it, created with certain Style settings.

The canvases contain two (or more) histograms, and the stat boxes of all are drawn and moved such that they can all be seen.

I now open the file locally and would like to see my local style on the histograms. This works fine by either using gROOT->ForceStyle() or canvas->UseCurrentStyle(). In both cases however, the stats boxes are moved on top of each other and the histograms loose the LineColor which was set.
The color of the statbox border on the other hand is not changed.

I understand that when I set the current style, the position of the stat boxes is reset for all histograms, so here the question would be, if there is any way to prevent this from happening? I think the same basically applies to the histograms: the default line color is set when setting the current style even if these histogramms used to have other settings.

Maybe posed differently: Is there an elegant way to apply a set of TStyle settings to an already styled object without disturbing all the other variables?

I hope this is not too nebulous



When you save a canvas in a file, it is saved with all its graphics attributes. They have no “style” store in it, but simply the attributes. And if you do c->Draw() it is drawn with the built in attribute independently of the style settings.

To force the current style attributes to be applied to the canvases stored in the file you should do (as you said) gROOT->ForceStyle() before opening the file.

You said the “histogram loose its color line”… that’s normal as you forced new attributes on the canvas.

You said:

Is there an elegant way to apply a set of TStyle settings to an already styled object without disturbing all the other variables?

what do you call “the other variables” ?


things I want to change are e.g. the font in the axis, the size of the titles, labels, etc. Everything else should be untouched, i.e. line styles in histograms, OptStat, OptFit options.
What I would like is a method which I can call which applies all this changes to the canvas

If there is a histogram in the canvas, I can think of ways around as getting the histogram which was drawn first and then changing the attributes of its axis, but then how can I do it for a TGraph where the ListOfPrimitives() for the Canvas does only contain a Frame and the points of the Graph, i.e. no possibility to access TGraph::GetHistogram() or something else?

I hope this illustrates what I would like.



A saved TCanvas contains the TGraph not only the TFrame. I just tried. I get:

root [0] TFile a("c1.root");
root [1]
TFile**         c1.root
 TFile*         c1.root
  KEY: TCanvas  c1;1
root [2]
Canvas Name=c1 Title= Option=
 TCanvas fXlowNDC=0 fYlowNDC=0 fWNDC=1 fHNDC=1 Name= c1 Title=  Option=
  OBJ: TList    TList   Doubly linked list : 0
   TFrame  X1= 0.000000 Y1=-11.891207 X2=0.990000 Y2=10.803281
   OBJ: TGraph  Graph    : 0 at: 0x9a75b10
root [4] 

(c1 is a canvas I saved in a root file)

You can get the TGraph " Graph" and then change its attributes as you would do for an histogram.


ok, so this is how I can do it manually, but can I change e.g. the fonts for all objects in the canvas (Legend, Title, Labels, possibly TText or TLatex) without having to access the objects one by one? (And as stated above without destroying other things in the process when using gStyle->… gROOT->ForceStyle() )



I guess one way would be to make you own style. You can play with the style editor. You access it in TCanvas under the Edit menu. You can try to save the style in a macro as you can see all the attributes are saved in that macro. you can modify just a few of them compare to your reference style (the one in your canvas file). I am not sure I have answered your question…