Alignment of labels in TPaletteAxis at color boundaries

Dear Rooters,

I propose to implement an option for TPaletteAxis
which allows to put labels at the boundaries of the
colored boxes instead at the equidistant points provided
by TGaxis.
It requires about 30 lines of extra code in TPaletteAxis::Paint,
(see att git diff file) no extra field values in the class.

For the option name I propose “CJUST”: (Color JUSTified) since
no A is allowed which conflicts with option “A”: suppress axis.

I attach a diff against the current HEAD, an example macro
and its output which demonstrates the difference to the default.

Given my limited view on roots code I ask somebody more competent
(Olivier) to check possible side effects etc.

Cheers
Otto
paletteaxis.txt (2.2 KB)
hcalign.C (1.1 KB)
calign.pdf (32.3 KB)

1 Like

Hi Otto,

Olivier @couet is now in vacations. You should submit PR with your modifications and wait once he is back.
One also should verify that your proposed draw option “CJUST” does not clash with existing histogram draw options - there are many of them in histogram painter. Most probably, one should parse such option there - not in TPaletteAxis::Paint. But we should wait for Olivier.

Regards,
Sergey

Hi Otto,

That’s a nice option ! it differs a bit with the normal one in the sense the axis and ticks (black lines) are not drawn. May be that’s fine… What about when you have 255 colors ? I guess it is up to the user to use it only hone the palette has a few colors. As Sergey suggested can you make it as a git Pull Request ?

Cheers,
Olivier

Hi Olivier, Sergey,

Option “CJUST” :
As far as I checked it does not conflict with existing options.
Its not clear to me how to pass this simply from HistPainter
to TPaletteAxis (except via Option)

Axis+ticks:
I will try to implement it

255 colors:
Its up to the user to control that via SetContour…

Cheers
Otto

Hi Otto,

Yes Passing it as an option seems to be the best way. CJUST is ok.
So users will have to type:

h2-Draw("COLZ CJUST");

Is it ok for you to make it as a PR ?

This is now in the master. Thanks for the code and for merging.

1 Like

{
   gStyle->SetOptStat(0);
   TCanvas *c1 = new TCanvas("c1","exa_CJUST",300,10,400,400);
   TH2F *hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
   // Fill histograms randomly
   TRandom3 randomNum;
   Float_t px, py;
   for (Int_t i = 0; i < 25000; i++) {
      randomNum.Rannor(px,py);
      hpxpy->Fill(px,py);
   }
   hpxpy->SetMaximum(200);
   Double_t zcontours[5] = {0, 20, 40, 80, 120};
   hpxpy->SetContour(5, zcontours);
   hpxpy->GetZaxis()->SetTickSize(0.01);
   hpxpy->GetZaxis()->SetLabelOffset(0.01);
   gPad->SetRightMargin(0.13);
   hpxpy->SetTitle("User contours, CJUST");
   hpxpy->Draw("COL Z CJUST");
}