# Formatting (axis labels and more) on a multi-pad canvas

**URL:** <https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428>\
**Category:** ROOT\
**Created:** [November 12, 2008, 1:53pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428 "2008-11-12T13:53:26Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mks](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@mks](https://root-forum.cern.ch/u/mks)\
**Post date:** [November 12, 2008, 1:53pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/1 "2008-11-12T13:53:26Z")

</div>

Hello everyone,

I have got a macro which draws a number of two-dimensional histograms in a grid. In general it works more-or-less fine, there are however a few issues it would be great if you could comment upon:

1. After the histograms in question have been drawn, white gaps appear between some of them which I haven’t been able to get rid of. Any idea where these come from?

2. For some reason, the same value of size of axis labels and titles possesses different meaning for the first and the last column/row of histograms and for all the others. Is this a bug? If not, how can I force the same size on all of them?

3. In order to make labels on the horizontal axes not overlap I tried to make them vertical by calling hist-\>GetXaxis()-\>LabelsOption(“v”), however this results in the message “Warning in TAxis::Sort: Cannot sort. No labels” and no orientation change. Am I doing something wrong here?

4. More on messing around with axis labels. Instead of using vertical orientation I would rather reduce the number of labels printed on the screen. Is there a method for controlling this?

5. Axis labels again. How could I delete the final (top-/rightmost) labels from axes so that they don’t overlap with first (bottom-/leftmost) labels from their neighbour?

6. Last but not least, I would like to get a single colour palette for all the histograms on the canvas, stretched along the whole right side of the pads. Is there any sensible way of doing this? I tried simply using “colz” instead of “col” on one of the histograms but unfortunately this doesn’t seem to allow the palette to be stretched beyond the boundaries of that histogram’s pad.

I use ROOT 5.18.00 and 5.20.00, on x86 and amd64. Attached you will find the macro files, the required input file and a screenshot of the output I get.

All comments and suggestions will be appreciated!

 ![](https://root-forum.cern.ch/uploads/default/original/2X/3/3e161586842325d9f8970b138d39555bdc3003fa.png)  
  
[pTscan\_collection-cEtaPhi.root](https://root-forum.cern.ch/uploads/default/original/2X/9/9de5b47fcc8b45560baf603eef947fed8f8a31e5.root) (96.1 KB)  
[plotScan.C](https://root-forum.cern.ch/uploads/default/original/2X/6/662c705c88f1e2d9fe907b6dc9ad705a96071cd1.C) (2 KB)  
[makePadsHists.C](https://root-forum.cern.ch/uploads/default/original/2X/3/33a472e1821141317e6672a2285a6bca70fa7025.C) (4.11 KB)

---

<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:** [November 12, 2008, 2:47pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/2 "2008-11-12T14:47:12Z")

</div>

I am looking at your macro. I’ll let you know.

---

<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:** [November 12, 2008, 3:24pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/3 "2008-11-12T15:24:39Z")

</div>

> [@](#):
>
> 1. After the histograms in question have been drawn, white gaps appear between some of them which I haven’t been able to get rid of. Any idea where these come from?

I added:

```auto
                pad->SetFrameBorderMode(0);
                pad->SetBorderMode(0);
                pad->SetBorderSize(0);
```

in makePadsHists.C . It makes it better, other wise it seems to me that that some precision issue. When I save a PS file there is no gap.

> [@](#):
>
> 1. For some reason, the same value of size of axis labels and titles possesses different meaning for the first and the last column/row of histograms and for all the others. Is this a bug? If not, how can I force the same size on all of them?

You should use pixel font size for labels and title. The text size is by default a % of the pad size. As the pads do not have the same sizes you get different text sizes.  
[root.cern.ch/root/html/TAttText.html#T4](http://root.cern.ch/root/html/TAttText.html#T4)

```auto
   xxx->SetTextFont(43);
   xxx->SetTextSize(16);
```

Note that the size is in pixel in that case.

> [@](#):
>
> 1. In order to make labels on the horizontal axes not overlap I tried to make them vertical by calling hist-\>GetXaxis()-\>LabelsOption(“v”), however this results in the message “Warning in TAxis::Sort: Cannot sort. No labels” and no orientation change. Am I doing something wrong here?

Only alphanumeric labels can be drawn vertically.

> [@](#):
>
> 1. More on messing around with axis labels. Instead of using vertical orientation I would rather reduce the number of labels printed on the screen. Is there a method for controlling this?

```auto
 hpx->GetXaxis()->SetNdivisions(3);
```

[root.cern.ch/root/html/TAttAxis. … Ndivisions](http://root.cern.ch/root/html/TAttAxis.html#TAttAxis:SetNdivisions)

> [@](#):
>
> 1. Axis labels again. How could I delete the final (top-/rightmost) labels from axes so that they don’t overlap with first (bottom-/leftmost) labels from their neighbour?

Changing the number of divisions may help.

> [@](#):
>
> 1. Last but not least, I would like to get a single colour palette for all the histograms on the canvas, stretched along the whole right side of the pads. Is there any sensible way of doing this? I tried simply using “colz” instead of “col” on one of the histograms but unfortunately this doesn’t seem to allow the palette to be stretched beyond the boundaries of that histogram’s pad.

The palette is drawn in the pad and cannot exit it. To have a big palette you should create a new pad and draw the palette in it. I found a example which may give you ideas:

```auto
{
   TH2D* h = new TH2D("h", "Example Histo", 20,-1,1,20,-1,1);
   h->FillRandom("gaus", 1E6);
   h->Draw("COLZ");
   gPad->Update();
   TPaletteAxis* zaxis = (TPaletteAxis*)h->GetListOfFunctions()->FindObject("palette")->Clone("MyPalette");
   delete c1;
   delete h;

   TCanvas* pc = new TCanvas("pc", "PaletteCanvas", 50,500);

   pc->cd();
   zaxis->SetX1NDC(0.);
   zaxis->SetX2NDC(1.);
   zaxis->SetY1NDC(0.);
   zaxis->SetY2NDC(1.);
   zaxis->Draw();
   gPad->Modified();
   gPad->Update();
}
```

---

<div class="post-metadata">

**Author:** ![delaossa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/delaossa/32/12319_2.png) [@delaossa](https://root-forum.cern.ch/u/delaossa)\
**Post date:** [September 17, 2013, 1:33pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/4 "2013-09-17T13:33:16Z")

</div>

Dear rooters,

I am struggling with the text formatting in a multi-pad canvas as well.  
Here is my macro:  
[testCanvasPartition.C](https://root-forum.cern.ch/uploads/default/original/2X/c/ce921e152a7ca17db42d49766acd30d124df98f8.C) (4.48 KB)

I know that label and title sizes are expressed in percentage of the pad size.  
The macro is intended to account for that and produce the same sizes and offset, etc. for every pad in the canvas.  
However, it does not work properly and the text changes in size depending on the pad.

Please, would anybody help? I am in kind of a hurry.  
Also, I think this is a common problem for many of my colleagues dealing with multi-pad canvases.  
So what we learn here would be useful for others.

Cheers!

---

<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:** [September 17, 2013, 1:57pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/5 "2013-09-17T13:57:35Z")

</div>

Divide() is not very clever and does not take into account the fact that the left column as wider left margins.  
Some time ago I wrote the attached macro which takes that into account.  
[div2.C](https://root-forum.cern.ch/uploads/default/original/2X/9/9bba1d14374eef3c5faa9835c3169b622f1d29bf.C) (1.55 KB)

---

<div class="post-metadata">

**Author:** ![delaossa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/delaossa/32/12319_2.png) [@delaossa](https://root-forum.cern.ch/u/delaossa)\
**Post date:** [September 17, 2013, 2:10pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/6 "2013-09-17T14:10:29Z")

</div>

Hi! I am sorry, but I don’t understand your answer…  
I am not using Divide(), but actually something rather similar to what you do in your macro.  
Still in your example, tick lengths for instance are not equally sized.

The idea in my example is to resize everything taking into account the actual height and weight of each pad in a way that everything looks the same.  
That shouldn’t be so difficult, but somehow it doesn’t work.

---

<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:** [September 17, 2013, 2:22pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/7 "2013-09-17T14:22:14Z")

</div>

Yes my macro does what you are trying to do, and the labels are all the save size. that’s what you wanted, no ?

---

<div class="post-metadata">

**Author:** ![delaossa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/delaossa/32/12319_2.png) [@delaossa](https://root-forum.cern.ch/u/delaossa)\
**Post date:** [September 17, 2013, 2:31pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/8 "2013-09-17T14:31:09Z")

</div>

No, it doesn’t.  
In your example there are no axis titles.  
As soon as I set a title for the histogram the title sizes, and the offsets change in every canvas.  
Also the ticks are not equally long in the pads in your original macro.

I upload here your macro with titles on axis:  
[div2mod.C](https://root-forum.cern.ch/uploads/default/original/2X/a/a6c0d813a023c01afde9ecc93cf607bf95a61bac.C) (1.76 KB)

---

<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:** [September 17, 2013, 2:44pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/9 "2013-09-17T14:44:56Z")

</div>

ha yes … right… this macro was originally written to make sure the all the plots have the same size. Now it should be extended some how to make sure the labels have also the same size. AS the border pads do not have the same size as this inner ones some scaling should be apply. Give me time to investigate.

---

<div class="post-metadata">

**Author:** ![delaossa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/delaossa/32/12319_2.png) [@delaossa](https://root-forum.cern.ch/u/delaossa)\
**Post date:** [September 17, 2013, 2:55pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/10 "2013-09-17T14:55:43Z")

</div>

Exactly, now you got it.  
The macro I have uploaded try to do this taking into account the size of every pad and “normalising” the labels, texts, ticks, etc. to get the same final sizes for every pad.  
However it is not working properly, and I don’t understand why.

---

<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:** [September 17, 2013, 3:02pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/11 "2013-09-17T15:02:02Z")

</div>

Well it is clear. Back to my macro if you do:

```auto
         pad = new TPad(name,name,x1,y1,x2,y2,0);
         printf("%g\n",y2-y1);
```

you get:

```auto
0.314685
0.314685
0.314685
0.22028
0.22028
0.22028
0.22028
0.22028
0.22028
0.244755
0.244755
0.244755
```

there is 3 sizes of pad (left right inner). Now I have looking at a way to get one as ref and compute the normalizing factor to be use in each SetSize for each pad… Not there yet.

---

<div class="post-metadata">

**Author:** ![delaossa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/delaossa/32/12319_2.png) [@delaossa](https://root-forum.cern.ch/u/delaossa)\
**Post date:** [September 17, 2013, 3:05pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/12 "2013-09-17T15:05:19Z")

</div>

Hi, I invite you to use the macro I have uploaded “testCanvasPartition.C” .  
I already did some work in that respect.

---

<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:** [September 17, 2013, 3:09pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/13 "2013-09-17T15:09:05Z")

</div>

I prefer to start from my and have fresh ideas about it…

---

<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:** [September 17, 2013, 3:31pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/14 "2013-09-17T15:31:29Z")

</div>

It looks ok in the attached macro (I tested the size of the Y labels);  
[div2.C](https://root-forum.cern.ch/uploads/default/original/2X/3/316bf4cd117c7ca797fd10927a02e740f69775ab.C) (1.73 KB)

---

<div class="post-metadata">

**Author:** ![delaossa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/delaossa/32/12319_2.png) [@delaossa](https://root-forum.cern.ch/u/delaossa)\
**Post date:** [September 17, 2013, 4:19pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/15 "2013-09-17T16:19:12Z")

</div>

Hi, this I got it too: To have same sizes in y axis.  
Surprisingly the trick does not work the same with x axis labels.  
make a try, you will see…

---

<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:** [September 18, 2013, 7:36am UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/16 "2013-09-18T07:36:33Z")

</div>

an other way for the text is to use the precision 3 (text size specified in pixel) (like 133 for times instead of 132)  
I will see for the ticks

---

<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:** [September 18, 2013, 8:34am UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/17 "2013-09-18T08:34:48Z")

</div>

I do not have a solution yet for the tick.  
As you said you need something quickly  
I guess the only way is to adjust them visually.  
Still looking…

---

<div class="post-metadata">

**Author:** ![delaossa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/delaossa/32/12319_2.png) [@delaossa](https://root-forum.cern.ch/u/delaossa)\
**Post date:** [September 18, 2013, 10:52am UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/18 "2013-09-18T10:52:29Z")

</div>

Hello, I have found the solution to all these problems:

- Fonts are defined with fix size (instead of in percentages of the pad size) using the font “precision 3” trick.
- When this is done, the offsets are setup in pixel size too, and thus, do not depend on the pad size.
- Last but not least, the tick sizes: These always will depend on the current pad because their sizes are always given as fractions of the canvas size. To compensate this effect, one needs to “normalize” the tick’s size to the actual height and width of the current pad.

To see how more in details, check this macro out:  
[testCanvasPartition.C](https://root-forum.cern.ch/uploads/default/original/2X/1/10148d91534cbc25dc3be3e87c4e5da0955262f4.C) (4.71 KB)

Cheers!  
Alberto

---

<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:** [September 18, 2013, 12:27pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/19 "2013-09-18T12:27:20Z")

</div>

Good ! I had some others matters to look at and therefore stop investigating. I will look again at your example and maybe add it in the standard examples (if you agree).

---

<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:** [September 18, 2013, 1:19pm UTC](https://root-forum.cern.ch/t/formatting-axis-labels-and-more-on-a-multi-pad-canvas/7428/20 "2013-09-18T13:19:32Z")

</div>

I added a new example: [canvas2.C](https://root.cern/doc/master/canvas2_8C.html)
