Two easy pieces (questions on drawing)

Hi fellow Rooters,

I have two sunday coffee questions, not exactly difficult, but annoyances in my everyday workflow.

The first, where did the implicit removal of “SAME” go?
In previous releases it was possible to add “SAME” as a goption even to the first histogram on the stack. This makes it so much easier drawing histograms in a loop, am I missing something?

The second question. Is there a color “iterator”? When drawing multiple histograms, specifying colors for each of them is a bit annoying, is it possible to “auto-colorize” histograms (if the canvas knows more objects are drawn on it, can it give them each a unique color)?

Cheers,

Morten

What are you talking about exactly ? do you have an example ?

No.

[quote=“couet”][quote]
The first, where did the implicit removal of “SAME” go?
In previous releases it was possible to add “SAME” as a goption even to the first histogram on the stack. This makes it so much easier drawing histograms in a loop, am I missing something?

What are you talking about exactly ? do you have an example ?
[/quote][/quote]

If you have more than one histogram (h1, h2,…, hn)

This works:

h1.Draw()
h2.Draw(“SAME”)
h3.Draw(“SAME”)…

But

h1.Draw(“SAME”)
h2.Draw(“SAME”)

Doesn’t. It is a bit of a hassle to do a special check for the first histogram, but it seemed to work in earlier releases (<5.25 I think).
Not having ROOT handling this trivial case in a neat way, systematically adds ~3 lines of boilerplate code to my scripts every time I have to draw more than one histogram of the same type on to of another.

Example code:

root [0] TH1F h1("h1","h1",100,-1,1)
root [1] h1.FillRandom("gaus",100)
root [2] TH1F h2("h2","h2",100,-1,1)
root [3] h2.FillRandom("gaus",100)

// Fails, in cint-mode something is drawn but the axes are mangled/missing, in compiled code it just fails to draw anything
root [4] h1.Draw("SAME")
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [5] h2.Draw("SAME")

// Works as expected, h1 is drawn and defines axes
root [6] TCanvas c2("c2")
root [7] h1.Draw()
root [8] h2.Draw("SAME")




I do not think this ever worked.
Any way it looks very dangerous seems to me, and if it was removed that’s a good thing !

If you want to treat the histograms all the same manner, the clean way would be to use a THStack.
The Add() command will be the same for all histograms and then at the end you draw the stack
with option “nostack”.

That’s equivalent as the multiple SAME as you are doing with, as bonus, the computation of the best frame fitting
all the histograms.

[quote=“couet”]I do not think this ever worked.
Any way it looks very dangerous seems to me, and if it was removed that’s a good thing !

If you want to treat the histograms all the same manner, the clean way would be to use a THStack.
The Add() command will be the same for all histograms and then at the end you draw the stack
with option “nostack”.

That’s equivalent as the multiple SAME as you are doing with, as bonus, the computation of the best frame fitting
all the histograms.[/quote]

Ah perfect, I tried with a THStack, but I missed the “nostack” option, thank you.