Managing a palette

Hello,
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”);
palette->SetLabelFont(42);
palette->SetLabelSize(0.030);
palette->SetX1NDC(0.905);
palette->SetX2NDC(0.918);
palette->GetAxis()->SetDecimals(kTRUE);
palette->GetAxis()->SetMaxDigits(3);
palette->GetAxis()->SetNoExponent(kFALSE);

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

I attached a small script about this.

Thanks a lot,
Barbara
tmp_histo.py (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,
Barbara

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,
Barbara