X-Axis range and Draw("same")


I would like to plot several histograms in the same pad using Draw(“same”). These histograms have different (but overlapping x-range). I have tried to use

histo->GetXaxis()->SetRangeUser(1.3, 2.1)

to expand the range, but it has not worked.

Ideally, it would really be nice if the “same” option could be flagged to recalculate the x and y ranges automatically. How would you recomend that I accomplish my task?


Use the class THStack.

see examples in tutorials hstack.C, cernstaff.C, limit.C, multicolor.C


Hi Rene,

Thanks for this information, it has been very helpful, but I would like to take it further.

I have more than one object of type THStack which share some of thier histograms (i.e. I have Added a single histogram to more than one stack.) I would like to plot these two stacks in the same canvas, but the histogram that they share should have different attributes (e.g. colour). Obviously, when I change these attributes and redraw the canvas, all the versions of the histogram will have the new attributes.

Would it be possible to implement a DrawCopy method for the THStack class? Alternatively, how else would you recommend I accomplish this?


Add a clone of your histograms to the stack, eg
THStack *s;
TH1 *h1, *h2;