Two adjacent Graphs

Hi everyone,

I would like to plot, one above the other, two different Graphs, with same range both for X and Y axis. I had a look on the tutorial webpage, and I found something similar using histograms.
I tried to follow the procedure and what I get finally are the two Graphs one above the other, but without title, axis and ticks…only the plots!

Could you please give me any useful suggestion?

Thanks!

Your are probably missing the option A in the Draw() method call.
If not send a small script reproducing the problem

Hi, thanks for answering!

This is the link to the tutorial I refer to:

root.cern.ch/root/html/tutorials … nes.C.html

My code is similar but instead of histograms I use Graphs. I if I draw with the option A, two graphs appear but separate, each with its axis, as usual when I divide a Canvas. But now I would like to keep them adjacent like in the tutorial.

send a small macro reproducing your problem. I will fix it … that’s easier than long explanations.

Ok, this is a simplified version of my code, the same graph is plotted, but if you run the macro you will get the problem I mentioned:

int TEST() { 

  gROOT->SetStyle("Plain");
  

  TCanvas *c1 = new TCanvas("c1","multipads",900,700);
  c1->Divide(1,2);
  gStyle->SetOptStat(0);


  /* photons data after 45Gy */
  double time[6] = {0., 15., 30., 60., 90., 120.};
  double data[6] = {1., 0.62, 0.43, 0.32, 0.19, 0.14};
  double err[6] = {0., 0.65, 0.45, 0.34, 0.21, 0.17};
  double ex[6] = {0.};

  for(int ii=0; ii<6; ii++){
   err[ii] = err[ii] - data[ii];
  }
  
  TGraphErrors *expBELLI = new TGraphErrors(6, time, data, ex, err);  
  

  
  c1->cd(1);
  
  TPad *pad_AAA = new TPad("pad_AAA","pad_AAA",0,0,1,1);
  pad_AAA->SetTickx(2);
  pad_AAA->Range(0.,0.05,200.0,1.0);
  pad_AAA->Draw();
  pad_AAA->cd();
  
  
  expBELLI -> SetMarkerStyle(20);
  expBELLI -> SetMarkerSize(2);
  expBELLI->Draw("p");


  c1->cd(2);
  TPad *pad_BBB = new TPad("pad_BBB","pad_BBB",0,0,1,1);
  pad_BBB->SetGrid();
  pad_BBB->SetTickx(2);
  pad_BBB->Range(0.,0.05,200.0,1.0);
  pad_BBB->Draw();
  pad_BBB->cd();

  expBELLI->Draw("p");



    return 0;
}

Thanks for your help!

{
  TCanvas *c1 = new TCanvas("c1","multipads",900,700);
  c1->Divide(1,2,0,0);
  gStyle->SetOptStat(0);

  double time[6] = {0., 15., 30., 60., 90., 120.};
  double data[6] = {1., 0.62, 0.43, 0.32, 0.19, 0.14};
  double err[6] = {0., 0.65, 0.45, 0.34, 0.21, 0.17};
  double ex[6] = {0.};

  for (int ii=0; ii<6; ii++) err[ii] = err[ii] - data[ii];

  TGraphErrors *expBELLI = new TGraphErrors(6, time, data, ex, err);

  expBELLI -> SetMarkerStyle(20);
  expBELLI -> SetMarkerSize(2);
  c1->cd(1);
  expBELLI->Draw("ap");


  c1->cd(2);
  expBELLI->Draw("ap");
}
int TEST() {

  gROOT->SetStyle("Plain");
 

  TCanvas *c1 = new TCanvas("c1","multipads",900,700);
  c1->Divide(1,2,0,0);
  gStyle->SetOptStat(0);


  /* photons data after 45Gy */
  double time[6] = {0., 15., 30., 60., 90., 120.};
  double data[6] = {1., 0.62, 0.43, 0.32, 0.19, 0.14};
  double err[6] = {0., 0.65, 0.45, 0.34, 0.21, 0.17};
  double ex[6] = {0.};

  for(int ii=0; ii<6; ii++){
   err[ii] = err[ii] - data[ii];
  }
 
  TGraphErrors *expBELLI = new TGraphErrors(6, time, data, ex, err); 
 

 
  c1->cd(1);
 
#if 0
  TPad *pad_AAA = new TPad("pad_AAA","pad_AAA",0,0,1,1);
  pad_AAA->SetTickx(2);
  pad_AAA->Range(0.,0.05,200.0,1.0);
  pad_AAA->Draw();
  pad_AAA->cd();
#endif
 
 
  expBELLI -> SetMarkerStyle(20);
  expBELLI -> SetMarkerSize(2);
  expBELLI->Draw("ap");


  c1->cd(2);
#if 0
  TPad *pad_BBB = new TPad("pad_BBB","pad_BBB",0,0,1,1);
  pad_BBB->SetGrid();
  pad_BBB->SetTickx(2);
  pad_BBB->Range(0.,0.05,200.0,1.0);
  pad_BBB->Draw();
  pad_BBB->cd();
#endif

  expBELLI->Draw("ap");



    return 0;
}

At least Pepe and I agree :slight_smile:

Thank for your answers, but maybe my explanation was not enough. I would like to obtain something like the canvas shown in the tutorial, of course only with two pads.
I mean, I would like to plot a canvas where the X axis of the upper Graph is the top of the one below. Of course, the code you sent me works, but they are still two separate Graphs.

Do you think you can help me to solve this problem?

Thanks

Maybe you want this:

int TEST() {

  gROOT->SetStyle("Plain");
 

  TCanvas *c1 = new TCanvas("c1","multipads",900,700);
  c1->Divide(1,2,0,0);
  gStyle->SetOptStat(0);


  /* photons data after 45Gy */
  double time[6] = {0., 15., 30., 60., 90., 120.};
  double data[6] = {1., 0.62, 0.43, 0.32, 0.19, 0.14};
  double err[6] = {0., 0.65, 0.45, 0.34, 0.21, 0.17};
  double ex[6] = {0.};

  for(int ii=0; ii<6; ii++){
   err[ii] = err[ii] - data[ii];
  }
 
  TGraphErrors *expBELLI = new TGraphErrors(6, time, data, ex, err); 
 

 
  c1->cd(1);
  gPad->SetTickx(2);
  gPad->SetTicky(2);
 
#if 0
  TPad *pad_AAA = new TPad("pad_AAA","pad_AAA",0,0,1,1);
  pad_AAA->SetTickx(2);
  pad_AAA->Range(0.,0.05,200.0,1.0);
  pad_AAA->Draw();
  pad_AAA->cd();
#endif
 
 
  expBELLI -> SetMarkerStyle(20);
  expBELLI -> SetMarkerSize(2);
  expBELLI->Draw("ap");


  c1->cd(2);
  gPad->SetTickx(2);
  gPad->SetTicky(2);
#if 0
  TPad *pad_BBB = new TPad("pad_BBB","pad_BBB",0,0,1,1);
  pad_BBB->SetGrid();
  pad_BBB->SetTickx(2);
  pad_BBB->Range(0.,0.05,200.0,1.0);
  pad_BBB->Draw();
  pad_BBB->cd();
#endif

  expBELLI->Draw("ap");



    return 0;
}

BTW. On my screen, with ROOT 5.30, the most right vertical lines of the frames are not drawn. A clear bug somewhere - these lines are present in the “.ps” file.

it is enough to hadd

gPad->SetTickx(2);

after each cd() :

[…]
c1->cd(1);
gPad->SetTickx(2);
[…]

Well, we are getting closer to the solution, but we are not yet there, sorry! :wink:

I send you a picture to help you to get an idea of what I mean…for me it would be enough the first column, with two graphs instead of histograms.

I’ve just checked that the same problem (reported in my previous post here) is present in ROOT 5.28.
The “.ps”, “.eps” and “.pdf” pictures are fine, but the “.gif” file is broken in the same way as the screen picture.

Now I am lost because that is what you get without gPad->SetTickx(2);
Looks like we are entring an endless loop …

This is what I get, the graphs are not attached each other as in the previous picture I’ve posted. I don’t know if some offset parameter should be adjusted.


Anyway, if it’s not possible to easily solve this problem I will look for different solutions, but thanks a lot for your help.

The attached macro I get the attached picture.



baloo.C (633 Bytes)

That’s what I get (note the missing line in the right - that’s a bug in ROOT).

…and that’s exactly what I would like to have! Considering both your answer, it could be that there are some bugs in my ROOT version, which is 5.23/04!

Of course your version is very old … I am using the newest

Olivier, could you, please, run the code that I sent with your ROOT version. I get no “right-vertical-border-line” with ROOT 5.28 and 5.30 (as can be seen on the picture).