FindObject("palette") issue with python 2.6.2

Dear PyRoot expert,

I came across this strange behavior:
I was trying to retrieve the palette of an histogram, but depending on the Python/ROOT versions this seems to be not always possible.

To verify this, just have a look at these two snippets of code:

In Python:

from ROOT import TH2D,TCanvas
h = TH2D(“h”,“H”,10,0,10,10,0,10)
c = TCanvas(“c”,“C”)
print “palette = %s” %h.FindObject(“palette”)

–> output on Python 2.6.2, ROOT 5.22:
palette = None

Inside ROOT 5.22:

root [0] TH2D h(“h”,“H”,10,0,10,10,0,10)
root [1] h.SetBinContent(1,1,100)
root [2] TCanvas c(“c”,“C”)
root [3] h.Draw(“colz”)
root [4] h.FindObject(“palette”)
–> output:
(const class TObject*)0x8f03e78

So in the first case it is not possible to find the palette (None object) while the in C version this works perfectly (pointer different from NULL).

I tested the above Python code on another configuration: Python 2.5.4 and ROOT 5.18 and it worked nicely both on Python as in the ROOT interpreter.

Do you have any idea of what is going wrong?

Best regards,


you must update teh canvas

otherwise the palette object is not yet generated. When using the CINT command mode,
the canvas is always updated after each command.



as for python, it only updates the canvases after each line in interpreter mode, not when running the code as a script. Perhaps that’s what you see different between the two versions?


Dear Rene and Wlan,
thanks for your answers. As Rene said, I can confirm that by calling Update() it now runs correctly both in CINT and in Python with any version.

For the differences between the two Python versions it might be that in the case when Update was not being called automatically, I was using the Python interpreter embedded in Emacs, which corresponds to what Wlan says.

Thanks, again!