Two issues: 1) Shared plot axis in graph, 2) Mathcal font

Hello,

I am trying to replicate the attached plot in ROOT. Two issues:

  1. How do I share internal axes, i.e., merge axes internal to a n x n grid of plots. Is pad manipulation required, or is there a simple switch?

  2. ROOT does not recognize the latex “\mathcal” font command needed to make the stylized “M” for the y-axis title for the lower-most right plot. It is still not available (last posted referencing mathcal was in 2005)? If so, any recommendations on how to make a similarly-styled “M”?

Any help would be much appreciated!

Regards,

Joe Bernstein
Argonne National Lab
fig6.ps (38 KB)

With #mathcal the #ell symbol is also requested. They are not yet there. Sorry for that. The main reason was because there was not direct match between PS and Freetype for this, and therefore they are not straight forward to put in place. Also, some more urgent matters have always shown up and the implemetation has been postponed again and again… I know that not good reasons but that’s how it is.

Looking at yoru plots, it seems there is 2 differents scales on the same pad. For this there is an example in $ROOTSYS/tutorials/hist/transpad.C

Thanks for the quick reply.

Based on the reply, I take it there is no simple way to make plots that share axes, and that I need to build from scratch.

Below is my attempt to do this. I am making the axes by hand. How do I tell TGraph to use those axes? That is, I want graph g1 be in pad1 and to use axis11 for it’s x-axis and axis12 for it’s y-axis. I’m having a hard time figuring it out.

Thanks in advance!

================================

Double_t ymin = 0;
Double_t ymax = 2000;
Double_t dy = (ymax-ymin)/0.8; //10 per cent margins top and bottom
Double_t xmin = 0;
Double_t xmax = 5;
Double_t dx = (xmax-xmin)/0.8; //10 per cent margins left and right
Double_t fxmin1 = xmin-0.1xmax; Double_t fxmax1 = 1.1xmax;
Double_t fymin1 = -1.6; Double_t fymax1 = 17.6;
Double_t fxmin2 = fxmin1; Double_t fxmax2 = fxmax1;
Double_t fymin2 = -0.01; Double_t fymax2 = 0.11;

float x1[10],y1[10];

for (int i=0;i<=4;i++) {
x1[i] = i;
y1[i] = i*i;
cout << x1[i] << " " << y1[i] << endl;
}

TCanvas *c1 = new TCanvas(“c1”,“transparent pad”,200,10,700,500);
TPad *pad1 = new TPad(“pad1”,"",0,0,0.5,1,0);
TPad *pad2 = new TPad(“pad2”,"",0.5,0,1,1,0);

//compute the pad range with suitable margins
pad1->Range(xmin-0.1dx,ymin-0.1dy,xmax,ymax+0.1*dy);
pad1->Draw();
pad1->cd();

TGaxis *axis11 = new TGaxis(xmin,ymin,xmax,ymin,fxmin1,fxmax1,805,“C”);
TGaxis *axis12 = new TGaxis(xmin,ymin,xmin,ymax,fymin1,fymax1,805,“R”);
TGaxis *axis13 = new TGaxis(xmin,ymax,xmax,ymax,fxmin1,fxmax1,805,"-C");
TGaxis *axis14 = new TGaxis(xmax,ymin,xmax,ymax,fymin1,fymax1,805,"+U");
axis11->Draw(); axis12->Draw(); axis13->Draw(); axis14->Draw();

TGraph *g1 = new TGraph(5,x1,y1);
g1->Draw(“C”); g1->SetTitle("");
g1->GetXaxis()->SetTitle(“x”);
g1->GetYaxis()->SetTitle(“x^{2}”);
g1->GetXaxis()->CenterTitle(); g1->GetYaxis()->CenterTitle();
c1->cd();

//compute the pad range with suitable margins
pad2->Range(xmin,ymin-0.1dy,xmax+0.1dx,ymax+0.1*dy);
pad2->Draw();
pad2->cd();

TGaxis *axis21 = new TGaxis(xmin,ymin,xmax,ymin,fxmin2,fxmax2,805,“C”);
TGaxis *axis22 = new TGaxis(xmin,ymin,xmin,ymax,fymin2,fymax2,805,“U”);
TGaxis *axis23 = new TGaxis(xmin,ymax,xmax,ymax,fxmin2,fxmax2,805,"-C");
TGaxis *axis24 = new TGaxis(xmax,ymin,xmax,ymax,fymin2,fymax2,805,"+L");
axis21->Draw(); axis22->Draw(); axis23->Draw(); axis24->Draw();

The graph is drawn in the current pad coordinates system. TGaxis does not define the coordinates system, it produces a graphics output of an axis. I have attached a macro which shows a possible way to proceed.
graphs2scales.C (1.94 KB)

Hello,

Thanks for the reply.

Sorry, but I don’t think you understand what I am trying to do. I am trying to place, e.g., two plots side-by-side such that they share an axis (the right vertical axis of the left plot overlays the left vertical axis of the right plot). Please take another look at the plot that I am trying to replicate that I attached to my original post.

Thanks again for your time.

Best,

Joe

Ok here is an other try.
graphs2scales2.C (1.11 KB)

Thanks for that! DrawFrame is new to me and not in the lastest online user manual (that I could find) – very useful command.

Final issue, I hope:

According to the manual, SetTickx(2) and SetTicky(2) should produce ticks AND labels on the top and right axes, respectively, but the labels don’t appear for the code below

Thanks!

Joe

=====================================
c1 = new TCanvas(“c1”,“c1”,200,10,700,500);
c1->Divide(2,1,0,0);

// create first graph
c1->cd(1);
c1_1->DrawFrame(-0.5,-1,1.1,11);
c1_1->SetTickx(2);
c1_1->SetTicky(1);
Int_t n1 = 10;
Double_t x1[] = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95};
Double_t y1[] = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1};
Double_t ex1[] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05};
Double_t ey1[] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8};
gr1 = new TGraphErrors(n1,x1,y1,ex1,ey1);
gr1->SetMarkerColor(kBlue);
gr1->SetMarkerStyle(21);
gr1->Draw(“LP”);

// create second graph
c1->cd(2);
c1_2->DrawFrame(-0.5,-5,1.1,105);
c1_2->SetFillColor(0);
c1_2->SetTickx(2);
c1_2->SetTicky(2);
Int_t n2 = 10;
Float_t x2[] = {-0.28, 0.005, 0.19, 0.29, 0.45, 0.56,0.65,0.80,0.90,1.01};
Float_t y2[] = {0.82,3.86,7,9,10,10.55,9.64,7.26,5.42,2};
Float_t ex2[] = {.04,.12,.08,.06,.05,.04,.07,.06,.08,.04};
Float_t ey2[] = {.6,.8,.7,.4,.3,.3,.4,.5,.6,.7};
for (Int_t i=0;i<n2;i++) {
y2[i] *= 8;
ey2[i] *= 8;
}
gr2 = new TGraphErrors(n2,x2,y2,ex2,ey2);
gr2->SetMarkerColor(kRed);
gr2->SetMarkerStyle(20);
gr2->SetName(“gr2”);
gr2->Draw(“LP”);

//End graphing

do:

c1_1->SetTopMargin(0.07);
c1_2->SetTopMargin(0.07);

The labels are there but hidden because the top margin is 0.

Ah, so just because white canvas space is visible above the plots does not mean top labels will be visible.

One problem with this, though, is that if I do the concomitant thing for the right margin so that the tick labels are visible on the right axis for gr2, e.g.,

c1_2->SetRightMargin(0.07);

Then the box size for graph gr2 is reduced to admit the margin and is thus smaller than the box for gr1. Resizing does not seem to happen when the top margin is increased from zero.

I also just noticed that if I have more than one row of plots, e.g.:

c1->Divide(2,2,0,0);

the font size of the tick labels for the lower row of plots is larger than that for the upper row. It only happens for c1->Divide(2,2,0,0) and c1->Divide(2,2,0). The font sizes are the same for, e.g., c1->Divide(2,2) and c1->Divide(2,2,00.001,0.001). I tried explicitly setting font sizes, e.g.

gStyle->SetTextFont(63);
gStyle->SetTextSize(24);

But the size mis-match remains.

Attached is a sample plot showing both issues.
graphs2scales2.ps (30.3 KB)

can you send me the macro producing that plot ?

I should have done that to begin with, sorry.

===============================

{

gStyle->SetFillColor(0);
gStyle->SetCanvasColor(0);
gStyle->SetPadColor(0);
gStyle->SetFrameBorderMode(0);
gStyle->SetTextFont(63);
gStyle->SetTextSize(24);

c1 = new TCanvas(“c1”,“c1”,200,10,700,500);
c1->Divide(2,2,0,0);

// create first graph
c1->cd(1);
c1_1->DrawFrame(-0.5,-1,1.1,11);
c1_1->SetTicks(2,2);
c1_1->SetTopMargin(0.07);
//c1_1->SetRightMargin(0.07);
Int_t n1 = 10;
Double_t x1[] = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95};
Double_t y1[] = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1};
Double_t ex1[] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05};
Double_t ey1[] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8};
gr1 = new TGraphErrors(n1,x1,y1,ex1,ey1);
gr1->SetMarkerColor(kBlue);
gr1->SetMarkerStyle(21);
gr1->Draw(“LP”);

// create second graph
c1->cd(2);
c1_2->DrawFrame(-0.5,-5,1.1,105);
c1_2->SetTicks(2,2);
c1_2->SetTopMargin(0.07);
c1_2->SetRightMargin(0.07);
Int_t n2 = 10;
Float_t x2[] = {-0.28, 0.005, 0.19, 0.29, 0.45, 0.56,0.65,0.80,0.90,1.01};
Float_t y2[] = {0.82,3.86,7,9,10,10.55,9.64,7.26,5.42,2};
Float_t ex2[] = {.04,.12,.08,.06,.05,.04,.07,.06,.08,.04};
Float_t ey2[] = {.6,.8,.7,.4,.3,.3,.4,.5,.6,.7};
for (Int_t i=0;i<n2;i++) {
y2[i] *= 8;
ey2[i] *= 8;
}
gr2 = new TGraphErrors(n2,x2,y2,ex2,ey2);
gr2->SetMarkerColor(kRed);
gr2->SetMarkerStyle(20);
gr2->SetName(“gr2”);
gr2->Draw(“LP”);

// create third graph
c1->cd(3);
c1_3->DrawFrame(-0.5,-1,1.1,11);
c1_3->SetTicks(2,2);

gr3 = new TGraphErrors(n1,x1,y1,ex1,ey1);
gr3->SetMarkerColor(kBlue);
gr3->SetMarkerStyle(21);
gr3->Draw(“LP”);

// create fourth graph
c1->cd(4);
c1_4->DrawFrame(-0.5,-5,1.1,105);
c1_4->SetTickx();
c1_4->SetTicky();

gr4 = new TGraphErrors(n2,x2,y2,ex2,ey2);
gr4->SetMarkerColor(kRed);
gr4->SetMarkerStyle(20);
gr4->SetName(“gr2”);
gr4->Draw(“LP”);

char file2[50];
sprintf(file2,“graphs2scales2.eps”); c1->Print(file2);

}

The fact that the plot appears smaller when you change the margin is normal because Divide acts on the pads not on the plot inside the pads. To make the plots appear the same size it is a bit more tricky. I had this question in the past and I did a macro at that time doing that. I have included (and used) it is the attached example.
graphs2scales3.C (3.15 KB)

NICE!

Seems like that fix-up should be incorporated into ROOT. I’m sure I’m not the only one who wants to make an array of n x m plots (n,m > 1) with adjoining axes.

The font size for the axis labels for the lower row of plots is still larger than that for the upper row, though. The:

gStyle->SetTextFont(63);
gStyle->SetTextSize(24);

at the top of the script does not solve the problem.

Any insight into that?

That’s the label size which should be changed:

   gStyle->SetLabelFont(63,"X");
   gStyle->SetLabelFont(63,"Y");
   gStyle->SetLabelSize(10,"X"); 
   gStyle->SetLabelSize(10,"Y"); 

Yes, may be at some point this macro should be added as a method in TPad…

You’re not going to believe this, but adding:

gStyle->SetLabelFont(63,“X”);
gStyle->SetLabelFont(63,“Y”);
gStyle->SetLabelSize(10,“X”);
gStyle->SetLabelSize(10,“Y”);

causes the the top axes labels to disappear! Does this happen for you?

On a side note, as it stands, DividegPad rearranges the pad numbers from the default layout (for a 2x2 array of plots) of:

1 2
3 4

to:

3 4
1 2

Just thought I would point that out in case you wanted to modify it for future use.

may be that is because if this different numbering ?