# Alignment of labels in TPaletteAxis at color boundaries

**URL:** <https://root-forum.cern.ch/t/alignment-of-labels-in-tpaletteaxis-at-color-boundaries/32917>\
**Category:** Evolution Proposals, Apps & Ideas\
**Created:** [February 26, 2019, 9:33am UTC](https://root-forum.cern.ch/t/alignment-of-labels-in-tpaletteaxis-at-color-boundaries/32917 "2019-02-26T09:33:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![OSchaile](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/e495f1/32.png) [@OSchaile](https://root-forum.cern.ch/u/OSchaile)\
**Post date:** [February 26, 2019, 9:33am UTC](https://root-forum.cern.ch/t/alignment-of-labels-in-tpaletteaxis-at-color-boundaries/32917/1 "2019-02-26T09:33:05Z")

</div>

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](https://root-forum.cern.ch/uploads/default/original/3X/a/f/afe8a2d31dc58d4c08de2ee8a3835a444e731d36.txt) (2.2 KB)  
[hcalign.C](https://root-forum.cern.ch/uploads/default/original/3X/2/3/23d85d04dd5fb263942686f2fa2e0929dff7daa7.C) (1.1 KB)  
[calign.pdf](https://root-forum.cern.ch/uploads/default/original/3X/2/6/2623c0625596630e73f99ddce28eab55a75df07f.pdf) (32.3 KB)

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [February 26, 2019, 9:46am UTC](https://root-forum.cern.ch/t/alignment-of-labels-in-tpaletteaxis-at-color-boundaries/32917/2 "2019-02-26T09:46:56Z")

</div>

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](https://root.cern/doc/master/classTHistPainter.html). Most probably, one should parse such option there - not in TPaletteAxis::Paint. But we should wait for Olivier.

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 11, 2019, 4:06pm UTC](https://root-forum.cern.ch/t/alignment-of-labels-in-tpaletteaxis-at-color-boundaries/32917/3 "2019-03-11T16:06:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![OSchaile](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/e495f1/32.png) [@OSchaile](https://root-forum.cern.ch/u/OSchaile)\
**Post date:** [March 12, 2019, 8:43am UTC](https://root-forum.cern.ch/t/alignment-of-labels-in-tpaletteaxis-at-color-boundaries/32917/4 "2019-03-12T08:43:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 12, 2019, 9:23am UTC](https://root-forum.cern.ch/t/alignment-of-labels-in-tpaletteaxis-at-color-boundaries/32917/5 "2019-03-12T09:23:05Z")

</div>

Hi Otto,

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

```auto
h2-Draw("COLZ CJUST");

```

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

---

<div class="post-metadata">

**Author:** ![pamputt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pamputt/32/12526_2.png) [@pamputt](https://root-forum.cern.ch/u/pamputt)\
**Post date:** [October 2, 2019, 11:53am UTC](https://root-forum.cern.ch/t/alignment-of-labels-in-tpaletteaxis-at-color-boundaries/32917/6 "2019-10-02T11:53:54Z")

</div>

This is now in [the master](https://github.com/root-project/root/commit/7fe70570aab99d091dd4f786a47f13743965b425). Thanks for the code and for merging.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [October 2, 2019, 11:59am UTC](https://root-forum.cern.ch/t/alignment-of-labels-in-tpaletteaxis-at-color-boundaries/32917/7 "2019-10-02T11:59:09Z")

</div>

![47](https://root-forum.cern.ch/uploads/default/original/3X/5/3/5303f1a9e97b4090a4ac9ebe68649d6db77f95ff.png)

```auto
{
   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");
}

```
