I’ve defined my own style using TStyle. I select this style using style->cd() and then canvas->UseCurrentStyle(). However, the code loops over several divisions of the same canvas so canvas->UseCurrentStyle() is executed more than once. This causes plots in all divisions of the canvas except the last to consist of small black points. All commands such as SetMarkerColor() do not affect the plots. I’ve fixed this problem by only executing canvas->UseCurrentStyle() the first time the loop is entered, but would like to know if this is the expected behavior.
A trivial example is below. Notice that if you comment out the second c1->UseCurrentStyle() you get the expected result.
Thanks,
Pat
main()
{
gROOT->Reset();
TStyle *style = new TStyle("style","Style");
style -> SetPadColor (10);
style -> SetFrameLineWidth(2);
style -> SetLineWidth(2);
c1 = new TCanvas("c1","Test Canvas",200,10,600,400);
c1 -> Divide(1,2,0,0);
// Create histogram
TH1F* hist_1 = new TH1F("h1","Random Gaussian",50,-4,4);
hist_1->FillRandom("gaus",10000);
// Set style
style -> cd();
c1 -> UseCurrentStyle();
// First Plot
c1 -> cd(1);
hist_1 -> SetMarkerStyle(20);
hist_1 -> SetMarkerColor(4);
hist_1 -> DrawCopy("P");
hist_1 -> SetDirectory(NULL);
// Set style
//If the following line is commented out, the result is what is expected
////////////////////////
c1 -> UseCurrentStyle();
////////////////////////
// Second Plot
c1 -> cd(2);
hist_1 -> SetMarkerStyle(25);
hist_1 -> SetMarkerColor(2);
hist_1 -> DrawCopy("P");
hist_1 -> SetDirectory(NULL);
delete hist_1;
} //main
Also, in the above example (with c1 -> UseCurrentStyle() commented out) I get different widths for the frame borders. The top and right sides of the frames are of width 1 and the bottom and left sides of the frame are of width 2, as they should be. This behavior only occurs the first time I execute the script. If I execute the script again, all 4 sides of the frame have width 2. Can anybody explain this? I’m using Root Version 3.10/02.
When you call c1->UseCurrentStyle you force all objects in the canvas and the canvas itself to use the current style, ie your previous settings for the histogram are overwritten.
I do not understand your point with the wifdth. May be you are fooled by
the pad highlighting. Add the following line \ at the end of your script
c1->cd();
c1->cd() at the end of the script does not make a difference.
If I use just style->SetLineWidth(5) I get thick lines for the left and bottom axes and thin lines for the top and right axes. The lines around the title box and key are also thick. This occurs no matter how many times the script is executed. I have attached a file showing this. Do you know why only these two lines are not thick?
I discovered that if I use just style -> SetFrameLineWidth(5) I must put c1 -> UseCurrentStyle() before c1 -> Divide(1,2,0,0) to get thick axes lines the first time I execute the script. If the UseCurrentStyle is placed after Divide, the thick lines don’t appear the first time the script is executed.
Rene asked me to continue the discussion. I executed your macro but I did not get the width “problems” you mentionned. Actually the plot I get is diffrent from the PS file you sent (see attachement). Can you send me a macro corresponding to the PS you get and tell me exactly what you think is wrong. Sorry to if you have to repeat what you already said but, reading your posts, I did not really understand what for you is wrong.
The code below gives the plot I posted above. Notice the different thickness in the axes lines. Perhaps SetLineWidth(5) affects the axis lines with tick marks differently than the axis lines without the tick marks? SetFrameLineWidth(5) (which is commented out in this example) now works with the different placement of c1->UseCurrentStyle() with respect to c1->Divide(1,2,0,0).
In TStyle.h you can see that only two LineWidth have some specialization. the HistLineWidth and the FrameLineWidth. When you set the LineWidth to some specific value, all the object not being a Frame or a Hist take that value. In particular the Axis. That is why they become that thick.
For instance, if you do not change the LineWitdh and change the FrameLineWidth to 5 you will see that the frame will be thick but the tick marks will remain thin. So what you get is normal.