Managing a palette

I would like to manage a palette (for example changing its position, the label font size, …)
How can I make this piece of C++ code using PyROOT?

TPaletteAxis palette=(TPaletteAxis)myHPD_1->FindObject(“palette”);

The problem, is, clearly, the first line :slight_smile:

I attached a small script about this.

Thanks a lot,
Barbara (701 Bytes)

Python is dynamically typed, and PyROOT cleverly deals with C++ object types and inheritance. So in ROOT where FindObject() always returns a pointer to a TObject (which you can cast to a TPaletteAxis, if you know its type), PyROOT cleverly does this automatically, so just by calling

You will get a TPaletteAxis object called palette. Some PyROOT objects (I’m not sure if this will work in your situation, but it works for TFiles) go a step further and allow you to find objects within them just by asking for a member:

I hope this helps.

  • Peter

Dear Peter,
thanks for your kind reply. As you can see from the code that I’ve attached I’ve already done something very similar. Unfortunately none of the method you suggests helps me in retrieving the palette of the graph. What I obtain is always a None object.

Here comes the newbie question: where is the mistake? What is the correct/best way to retrieve and then manipulate the palette of a graph/histogram in PyROOT?

Thanks a lot,

I am sorry, I missed your ending comments about the attached script, and I didn’t see it.

You had the right idea, but you have to Draw(“colz”) before a palette is created. It is the Draw(“z”) command that creates the palette - before that it does not exist. The correct line is

I hope this helps.

  • Peter

Also after Draw(“colz”) a gPad->Update() (its Python equivalent in fact) is needed.

Thanks, with gPad->Update() it finally works!!! :smiley:
Thanks a lot,