I would suggest to add SetStats() method to the pop-up menu which appears when a TH1 is right-clicked. This would allow user to switch on/off statistics boxes via GUI.
I don not really understand the logic behind. The stat. box is one-to-one related to the histogram. I don’t see the point why the boxes’ display status is toggled via menu of a TCanvas. The user should have a possibility to (EASILY) select histograms to show statistics. Taking into account the facts that a TCanvas may have several TPads and a TPad may contain several TH1s, I would suggest the following: put a Stats on/off check box to the editor panel (associated with TH1).
Finally, I’ve encountered redrawing problems. If I change stat. box status via TCanvas window menu, canvas itself is not redrawn. I have to some clicks around to get it redrawn.
what to you mean by " changing the axis labels ?"[/quote]
An example. You load a TCanvas from a ROOT file and draw it. You see a plot with x-axis having label “E in GeV”. But you would prefer label “E (GeV)”. What do you do?
use the graphics editor, point to the axis and change the title.
You can generate the canvas.C file and see the relevant call to change
the axis tithe.
Yes this works, but imagine you need to do that 50 times… That is why I asked how to do it “programatically” .
[quote=“brun”]
You can generate the canvas.C file and see the relevant call to change
the axis tithe.[/quote]
I did so and it boils down to changing axis title of an histogram. My question was quite different. You have a pointer to a TCanvas and you want to change axis titles. You don’t care (or you don’t want to care) what is plotted in TCanvas and just change the axis title. In my opinion, this is a simple task (moreover a frequent one) which should be accomplished by simple means. The only solution I am aware of is to take list of primitives, take the first entry, check it is an histogram and change its axis labels. And this is far from being easy…
Thanks Rene. I didn’t really mean changing properties of the titles. I meant changing the text itself. Something like the non-existing function SetAxisLabels in the following example:
TFile *file = new TFile(...);
TCanvas *can = (TCanvas *) file->Get(...);
can->SetAxisLabels("E (GeV)", "count");
can->Draw(); // producing a plot with labels "E (GeV)" and "count"
TFile *file = new TFile(...);
TCanvas *can = (TCanvas *) file->Get(...);
can->SetAxisLabels("E (GeV)", "count");
The only thing you have is the pointer to TCanvas (you have no hpx to use!). Moreover you don’t want to bother about contents of the TCanvas. Wheter it comprises TH1x or TGraphs, how many, what is first, … The only desire is to modify axis labels.
The axis (TAxis) are objects part of the histogram (or graph) . The title axis title goes with axis (TAxis). The axis title aim is to give the legend to the data represented along the x,y or z axis. This title as nothing to do with the canvas, it is connected to the data set (histogram graph etc …). The link betwen these titles along the axis and the data is so strong that it is even possible to define them (the titles) in one go with the histogram title (see the convention). What you want is something not connected to the data at all. So you better use TLatex to paint such “titles”.
You may create a histogram and give titles to its axis, but the titles become only important when you plot the histogram. (of course you can print it on screen, but who does it…) And hence there is also strong link between the title and the canvas.
A very practical example. I performed resolution studies for our detectors. I had 3 histograms: resolution in x, resolution in y and combined (radial) resolution. The first one was called “res_x” and had (horizontal) axis title “resolution in x”. I wanted to have all three histograms plotted in the same canvas (the best way to compare the results), hence I did
res_x->Draw();
res_y->Draw("same");
res_c->Draw("same");
Indeed, the axis shown in canvas read “resolution in x”, which is relevant only for one of those three histograms. I wanted to change the title to “resolution” and explain the things in legend. Of course I could do
res_x->GetXaxis()->SetTitle("resolution");
This would change the shown title appropriately, but res_x histogram itself would have incompatible axis title. You see the problem? In my opinion there is a strong dependence between canvas and axes.
One more argument. You have 1 canvas, 1 (horizontal) axis and arbitrary objects plotted. How can be that the axis is more related to object (which one from the list?) that to the canvas?
I think it is quite nice that TH1x object has a axis and its title, but TCanvas should definitely have also axes. Moreover those of TCanvas should be independent on those of TH1x.