TPaletteAxis size

Hi!

I can’t find a way to edit the size and position of the TPaletteAxis.
Consider this example:

void test()
{
   TCanvas *c1 = new TCanvas("a", "b", 700, 700);
   TF2 *f = new TF2("f3","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);
   f->Draw("colz");
}

I would like to shrink the color palette drawn on the right:


Of course I could do that manually, but I want my macro to automatically save the the graph/hist it makes, without having the need to manually edit that.

Thank you! :slight_smile:

Use the example posted here (movepal.C):

https://root-forum.cern.ch/t/drawing-tpaletteaxis-in-a-different-pad/28161/3

:frowning_face:

I’m very bad at searching stuff, I see…

Thank you!

I still need some help…

What am I doing wrong here?

void test()
{
	TCanvas *c = new TCanvas();
	gStyle->SetOptStat(0);
	TH2D *h = new TH2D("h2","",40,-4,4,40,-20,20);
	Float_t px, py;
	for (Int_t i = 0; i < 25000; i++) {
		gRandom->Rannor(px,py);
		h->Fill(px,5*py);
	}

	gStyle->SetNumberContours(255);
	double contours[1] = {5};
	h->DrawCopy("colz");
	h->SetContour(1, contours);
	h->Draw("cont3 same");
	h->SetLineColor(kRed);

	c->Update();
	TPaletteAxis * palette = (TPaletteAxis *) h->GetListOfFunctions()->FindObject("palette");
	palette->SetX2NDC(0.93);
	c->Modified();
	c->Update();
}

The palette size doesn’t change, and I get an error message in the terminal.

TH1 *hh = h->DrawCopy("colz"); // creates all axes
// ...
TPaletteAxis * palette = (TPaletteAxis *) hh->GetListOfFunctions()->FindObject("palette");

So weird…
But it works. :man_shrugging:

An other (less weird) way:

void movepal2()
{
   TCanvas *c = new TCanvas();
   gStyle->SetOptStat(0);
   TH2D *h = new TH2D("h2","",40,-4,4,40,-20,20);
   Float_t px, py;
   for (Int_t i = 0; i < 25000; i++) {
      gRandom->Rannor(px,py);
      h->Fill(px,5*py);
   }

   TPaletteAxis *palette = new TPaletteAxis(4.040115,-19.94737,4.498567,-4.052632,h);
   h->GetListOfFunctions()->Add(palette);

   gStyle->SetNumberContours(255);
   double contours[1] = {5};
   h->DrawCopy("colz");

   h->SetContour(1, contours);
   h->Draw("cont3 same");
   h->SetLineColor(kRed);
   h->SetLineWidth(3);
}
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.