# Plotting mulitple Ntuples on the same set of axes

**URL:** <https://root-forum.cern.ch/t/plotting-mulitple-ntuples-on-the-same-set-of-axes/37375>\
**Category:** Newbie\
**Created:** [December 30, 2019, 11:12am UTC](https://root-forum.cern.ch/t/plotting-mulitple-ntuples-on-the-same-set-of-axes/37375 "2019-12-30T11:12:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![luiz\_iniciante](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/b9e5f3/32.png) [@luiz\_iniciante](https://root-forum.cern.ch/u/luiz_iniciante)\
**Post date:** [December 30, 2019, 11:12am UTC](https://root-forum.cern.ch/t/plotting-mulitple-ntuples-on-the-same-set-of-axes/37375/1 "2019-12-30T11:12:43Z")

</div>

Hello Forum,  
I’m trying to do something that, in principle, sounds easy, but is proving challenging to me.  
I have 3 Ntuples and would like to plot them on the same set of XY axes in the same style. I have written the following code to try to achieve this:

ntuple1-\>Draw(“Dose:Depth”, “”, “L”);  
TH1F _htemp = (TH1F_)gPad-\>GetPrimitive(“htemp”);  
htemp-\>SetTitle(“PDD of 6 MV Beam in PMMA”);  
htemp-\>SetMarkerColor(4);  
htemp-\>SetXTitle(“Depth (cm)”);  
htemp-\>GetXaxis()-\>SetRangeUser(0,15);  
htemp-\>GetXaxis()-\>CenterTitle();  
htemp-\>SetYTitle(“PDD %”);  
htemp-\>GetYaxis()-\>CenterTitle();  
ntuple2-\>Draw(“Dose:Depth”,"", “same”);  
ntuple3\>Draw(“Dose:Depth”,"", “same”);

However this gives me only the first Ntuple plotted in the style “L”, as a solid line. The remaining Ntuples still appear as points on the plot. I would like all 3 Ntuples to appear in the style “L”.

Another more minor question is about “htemp-\>SetTitle(“PDD of 6 MV Beam in PMMA”)”. What is the command to center it?

Thanks in advance,  
Ricardo

\_ROOT Version: 5.34  
\_Platform:Ubuntu Not Provided  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![pamputt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pamputt/32/12526_2.png) [@pamputt](https://root-forum.cern.ch/u/pamputt)\
**Post date:** [December 30, 2019, 1:45pm UTC](https://root-forum.cern.ch/t/plotting-mulitple-ntuples-on-the-same-set-of-axes/37375/2 "2019-12-30T13:45:16Z")

</div>

> [@luiz\_iniciante](#):
>
> ntuple2-\>Draw(“Dose:Depth”,“”, “same”);

Use `ntuple2->Draw(“Dose:Depth”,"", “L same”);` instead

---

<div class="post-metadata">

**Author:** ![luiz\_iniciante](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/b9e5f3/32.png) [@luiz\_iniciante](https://root-forum.cern.ch/u/luiz_iniciante)\
**Post date:** [December 31, 2019, 2:36am UTC](https://root-forum.cern.ch/t/plotting-mulitple-ntuples-on-the-same-set-of-axes/37375/3 "2019-12-31T02:36:31Z")

</div>

Thanks @pamputtt. I’m trying now to change the individual line colors. To my surprise `SetLineColor` seems to have no effect as I used it below:

ntuple1-\>Draw(“Dose:Depth”, “”, “L”);  
TH1F _htemp = (TH1F_)gPad-\>GetPrimitive(“htemp”);  
htemp-\>SetTitle(“PDD of 6 MV Beam in PMMA”);  
htemp-\>SetLineColor(kRed);  
htemp-\>SetXTitle(“Depth (cm)”);  
htemp-\>GetXaxis()-\>SetRangeUser(0,15);  
htemp-\>GetXaxis()-\>CenterTitle();  
htemp-\>SetYTitle(“PDD %”);  
htemp-\>GetYaxis()-\>CenterTitle();

```
   ntuple2->Draw("Dose:Depth","", "L same");
   htemp->SetLineColor(3);
   ntuple3->Draw("Dose:Depth","", "L same");
   htemp->SetLineCColor(2);

```

Perhap’s it’s because I’m a Newbie, but I find Ntuple very cumbersome for anything other than quickly filling data. Whenever one wants to do anything presentable with it, one has to cast it as a histogram which more or less reduces its role to a sort of middleman.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 1, 2020, 11:35am UTC](https://root-forum.cern.ch/t/plotting-mulitple-ntuples-on-the-same-set-of-axes/37375/4 "2020-01-01T11:35:33Z")

</div>

```cpp
  ntuple1->Draw("Dose:Depth", "", "L");
  TH2F *htemp = (TH2F*)gPad->GetPrimitive("htemp"); // 2D axes
  htemp->SetTitle("PDD of 6 MV Beam in PMMA;Depth (cm);PDD %");
  htemp->GetXaxis()->CenterTitle(); htemp->GetYaxis()->CenterTitle();
  htemp->GetXaxis()->SetRangeUser(0., 15.); // "shrink" the X range
  htemp->GetYaxis()->SetRangeUser(0., 150.); // "shrink" the Y range
  TGraph *graph = (TGraph*)gPad->GetPrimitive("Graph"); // 2D data
  graph->SetName("Graph1"); graph->SetLineColor(4);
  ntuple2->Draw("Dose:Depth", "", "L SAME");
  graph = (TGraph*)gPad->GetPrimitive("Graph"); // 2D data
  graph->SetName("Graph2"); graph->SetLineColor(3);
  ntuple3->Draw("Dose:Depth", "", "L SAME");
  graph = (TGraph*)gPad->GetPrimitive("Graph"); // 2D data
  graph->SetName("Graph3"); graph->SetLineColor(2);
  // gPad->ls();

```

---

<div class="post-metadata">

**Author:** ![luiz\_iniciante](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/b9e5f3/32.png) [@luiz\_iniciante](https://root-forum.cern.ch/u/luiz_iniciante)\
**Post date:** [January 2, 2020, 3:09am UTC](https://root-forum.cern.ch/t/plotting-mulitple-ntuples-on-the-same-set-of-axes/37375/5 "2020-01-02T03:09:01Z")

</div>

Thanks, Wile\_E\_Coyote. I see that the main thing is to cast the Ntuple as a 2D histogram. I have 2 additional questions:

1. How do I change the range of the Y-axis. I am unable to do it by the command

```auto
htemp->GetYaxis()->SetRangeUser(0., 150.);

```

1. How do I center the main title ( “PDD of 6 MV Beam in PMMA”)

Thanks in advance,  
RL

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 2, 2020, 7:58am UTC](https://root-forum.cern.ch/t/plotting-mulitple-ntuples-on-the-same-set-of-axes/37375/6 "2020-01-02T07:58:07Z")

</div>

1. It should work (note, however, that you can only “shrink” ranges).

2. You can play with the “[title](https://root.cern.ch/root/html534/TPaveText.html)”:

```cpp
  gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn
  TPaveText *title = (TPaveText*)gPad->GetPrimitive("title");
  title->Print();

```

---

<div class="post-metadata">

**Author:** ![pamputt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pamputt/32/12526_2.png) [@pamputt](https://root-forum.cern.ch/u/pamputt)\
**Post date:** [January 2, 2020, 9:22am UTC](https://root-forum.cern.ch/t/plotting-mulitple-ntuples-on-the-same-set-of-axes/37375/7 "2020-01-02T09:22:07Z")

</div>

> [@luiz\_iniciante](#):
>
> 1. How do I change the range of the Y-axis. I am unable to do it by the command
> 
> ```auto
> htemp->GetYaxis()->SetRangeUser(0., 150.);
> 
> ```

Try `htemp->SetMinimum(0.); htemp->SetMaximum(150.);`

---

<div class="post-metadata">

**Author:** ![luiz\_iniciante](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/b9e5f3/32.png) [@luiz\_iniciante](https://root-forum.cern.ch/u/luiz_iniciante)\
**Post date:** [January 2, 2020, 9:58am UTC](https://root-forum.cern.ch/t/plotting-mulitple-ntuples-on-the-same-set-of-axes/37375/8 "2020-01-02T09:58:42Z")

</div>

Thanks @pamputt and @Wile_E_Coyote. I tried the lines

```auto
htemp->SetMinimum(0.); htemp->SetMaximum(150.);

```

but to no effect.

It appears that I can only shrink the range on the Y-axis. But there must be some way to increase that range, since part of the data is cut out at the present. Any ideas?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 2, 2020, 12:07pm UTC](https://root-forum.cern.ch/t/plotting-mulitple-ntuples-on-the-same-set-of-axes/37375/9 "2020-01-02T12:07:24Z")

</div>

```auto
  TH2F *htemp = new TH2F("htemp", "PDD of 6 MV Beam in PMMA;Depth (cm);PDD %", 2, 0., 15., 2, 0., 150.); // 2D axes
  htemp->GetXaxis()->CenterTitle(); htemp->GetYaxis()->CenterTitle();
  htemp->SetStats(kFALSE); htemp->DrawCopy(""); delete htemp; // no longer needed (cleanup)
  ntuple1->Draw("Dose:Depth", "", "L SAME");
  TGraph *graph = (TGraph*)gPad->GetPrimitive("Graph"); // 2D data
  graph->SetName("Graph1"); graph->SetLineColor(4);
  // ...

```

---

<div class="post-metadata">

**Author:** ![luiz\_iniciante](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/b9e5f3/32.png) [@luiz\_iniciante](https://root-forum.cern.ch/u/luiz_iniciante)\
**Post date:** [January 3, 2020, 2:19am UTC](https://root-forum.cern.ch/t/plotting-mulitple-ntuples-on-the-same-set-of-axes/37375/10 "2020-01-03T02:19:06Z")

</div>

Thanks @Wile_E_Coyote. That worked a charm.

Beep beep.
