How to control Palette

Dear All,

I want to show palette for 2D plot. However, sometimes palette obscures x axis 10^n field. So I want to change the position of palette. Is there any way to change its position automatically? I can drag the palette manually in the canvas and generate a script of TPaletteAxis. But when I put TPaletteAxis to my code, the palette is not changed. Even I use SetX1, SetY1 or SetY1NDC to set the top and bottom corners of the palette, it still didn’t change position. The attachment is where I want to put the palette. I did this manually. My code is as below:

TCanvas *c1 = new TCanvas(“c1”,“c1”,600,400);
TH2F h2 = new TH2F(“h2”,"Example of a resized palette ",40,-4,4,40,-20,20);
Float_t px, py;
for (Int_t i = 0; i < 25000; i++) {
gRandom->Rannor(px,py);
h2->Fill(px,5
py);
}
gStyle->SetPalette(1);
h2->Draw(“COLZ”);
gPad->Update();
TPaletteAxis palette = (TPaletteAxis)h2->GetListOfFunctions()->FindObject(“palette”);
// palette->SetY1NDC(0.9);
// palette->SetY2NDC(0.09);
palette->SetX1(6.7);
palette->SetY1(-20);
palette->SetX2(7.6);
palette->SetY2(20);
return c1;

Any advice would be appreciated! Thank you very much in advance :slight_smile:

Best regards!
Palette.pdf (17.5 KB)

You can move the palette like the attached example.
movepal.C (2.42 KB)

Thanks a lot, Couet!