# Two adjacent Graphs

**URL:** <https://root-forum.cern.ch/t/two-adjacent-graphs/13644>\
**Category:** ROOT\
**Created:** [January 20, 2012, 1:42pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644 "2012-01-20T13:42:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Baloo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@Baloo](https://root-forum.cern.ch/u/Baloo)\
**Post date:** [January 20, 2012, 1:42pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/1 "2012-01-20T13:42:42Z")

</div>

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!

---

<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:** [January 20, 2012, 2:10pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/2 "2012-01-20T14:10:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Baloo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@Baloo](https://root-forum.cern.ch/u/Baloo)\
**Post date:** [January 20, 2012, 2:18pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/3 "2012-01-20T14:18:54Z")

</div>

Hi, thanks for answering!

This is the link to the tutorial I refer to:

[root.cern.ch/root/html/tutorials … nes.C.html](http://root.cern.ch/root/html/tutorials/graphs/zones.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.

---

<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:** [January 20, 2012, 2:35pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/4 "2012-01-20T14:35:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Baloo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@Baloo](https://root-forum.cern.ch/u/Baloo)\
**Post date:** [January 20, 2012, 2:52pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/5 "2012-01-20T14:52:31Z")

</div>

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:

```auto
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!

---

<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:** [January 20, 2012, 3:22pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/6 "2012-01-20T15:22:12Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [January 20, 2012, 3:23pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/7 "2012-01-20T15:23:34Z")

</div>

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

---

<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:** [January 20, 2012, 3:26pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/8 "2012-01-20T15:26:39Z")

</div>

At least Pepe and I agree 🙂

---

<div class="post-metadata">

**Author:** ![Baloo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@Baloo](https://root-forum.cern.ch/u/Baloo)\
**Post date:** [January 20, 2012, 3:29pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/9 "2012-01-20T15:29:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [January 20, 2012, 3:29pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/10 "2012-01-20T15:29:53Z")

</div>

Maybe you want this:

```auto
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.

---

<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:** [January 20, 2012, 3:38pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/11 "2012-01-20T15:38:32Z")

</div>

it is enough to hadd

gPad-\>SetTickx(2);

after each cd() :

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

---

<div class="post-metadata">

**Author:** ![Baloo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@Baloo](https://root-forum.cern.ch/u/Baloo)\
**Post date:** [January 20, 2012, 3:44pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/12 "2012-01-20T15:44:02Z")

</div>

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

![](http://root.cern.ch/phpBB3/download/file.php?id=392&mode=view)

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.

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [January 20, 2012, 3:46pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/13 "2012-01-20T15:46:23Z")

</div>

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.

---

<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:** [January 20, 2012, 3:48pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/14 "2012-01-20T15:48:11Z")

</div>

> [@](#):
>
> for me it would be enough the first column, with two graphs instead of histograms.

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

---

<div class="post-metadata">

**Author:** ![Baloo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@Baloo](https://root-forum.cern.ch/u/Baloo)\
**Post date:** [January 20, 2012, 3:55pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/15 "2012-01-20T15:55:50Z")

</div>

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.

 ![](https://root-forum.cern.ch/uploads/default/original/2X/d/d5d185859f66b63eaac76063064feea4327c6e59.gif)  

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

---

<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:** [January 20, 2012, 4:02pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/16 "2012-01-20T16:02:06Z")

</div>

The attached macro I get the attached picture.

 ![](https://root-forum.cern.ch/uploads/default/original/2X/1/1857aaf7540a152f955421afa3559cc701da369b.png)  
  
[baloo.C](https://root-forum.cern.ch/uploads/default/original/2X/4/4b3e66115bd5db68096c7f0fd21e7ed8c00900b4.C) (633 Bytes)

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [January 20, 2012, 4:02pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/17 "2012-01-20T16:02:22Z")

</div>

That’s what I get (note the missing line in the right - that’s a bug in ROOT).  
 ![](https://root-forum.cern.ch/uploads/default/original/2X/b/b802a22434e748b0cba2de72f15e796656f61cd4.gif)

---

<div class="post-metadata">

**Author:** ![Baloo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@Baloo](https://root-forum.cern.ch/u/Baloo)\
**Post date:** [January 20, 2012, 4:07pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/18 "2012-01-20T16:07:35Z")

</div>

> [@](#):
>
> The attached macro I get the attached picture.

…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!

---

<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:** [January 20, 2012, 4:09pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/19 "2012-01-20T16:09:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [January 20, 2012, 4:16pm UTC](https://root-forum.cern.ch/t/two-adjacent-graphs/13644/20 "2012-01-20T16:16:58Z")

</div>

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).

[Next page](https://root-forum.cern.ch/t/two-adjacent-graphs/13644.md?page=2)
