Histogram label sizes for several pads in a canvas

Hi all,

I feel pretty stupid with my problem while drawing several histograms in a number of pads with no margins between the pads.

It is probably easiest to see after executing the following few lines:

int n = 3;
TCanvas *c = new TCanvas( “c”, “c”, 10, 10, 400, 600 );
c->SetBottomMargin( 0.15 );
c->Divide( 1, n, 0.01, 0 );

char hname[200];
for( int i = 0; i < n; i++ )
c->cd( i+1 );
gPad->SetGridx( 0 );
gPad->SetGridy( 0 );
gPad->SetTickx( 0 );
gPad->SetTicky( 0 );
gPad->SetRightMargin( 0.01 );
sprintf( hname, “h_%d”, i );
TH1D *h = new TH1D( hname, “”, 100, 0., 1. );
h->SetStats( 0 );
h->GetXaxis()->SetLabelSize( 0.1 );
h->GetYaxis()->SetLabelSize( 0.1 );
h->GetYaxis()->SetNdivisions( 410, true );

Why are the labels in the y-axis in the bottom histogram larger than in the other histograms? How can I fix that?

I am using root version 5.12/00.



By default the text/label size is a percentage of the vertical pad size. Here you set 10% (0.1). When a canvas is splitted using Divide(), the pads generated do not have all the same vertical size because of the different margins. To bypass this problem it is enough to define the labels’ size in a way independant from the pad size. This can be achieved using a pixel size instead of a % size. In the “for loop” simply do:

                h->GetYaxis()->SetLabelFont( 63  );
                h->GetYaxis()->SetLabelSize( 12 );

instead of:

                h->GetYaxis()->SetLabelSize( 0.1 );

See: root.cern.ch/root/html/TAttText.html for details about text font and precision.

Thanks for the answer couet! Unfortunately the problem reappears when trying to print the canvas to a pdf or eps. Here is an example to demonstrate my problem:
fontSizePad.C (649 Bytes)

This does seem to go away if if printing to say a png, but I’d rather like to be able to use a pdf here. Any suggestions?

The ps files generated by your macro look fine for me. Which ROOT version are you using ?
I tried with 5.34 on Mac.

I’m using 5.30/06 on Mint12 (x86_64 gcc 4.6.1). I’ll see about updating :slight_smile:

So I am using the current root trunk. I was pleasently surprised to find that gcc 4.6 compiles it without complaints now =D>

My config flags were:

--prefix=/usr/local/ --enable-asimage --enable-gviz --enable-gsl-shared \ --enable-mathmore --enable-minuit2 --enable-opengl --enable-python \ --enable-roofit --enable-rpath --enable-shared --enable-soversion --enable-tmva \ --enable-x11 --enable-xft

The problem however remains unchanged, script and produced pdfs are attached.
test.pdf (12.3 KB)
reference.pdf (12.3 KB)
fontSizePad.C (649 Bytes)

When a canvas is split using Divide(x,x,0,0), the pads generated do not have all the same vertical sizes because of the different margins. Using the font 43 will work on screen and png but PS and PDF are vector outputs and the size in points do not exist there. I did some print outs in the PS code, and running your macro it is clear that the bottom pad in the “test” case has different parameters. I am afraid that making changes there will have many bad side effects, and anyway you have a fall back solution with the technique you are using to produce reference.ps.