# Ratio plot

**URL:** <https://root-forum.cern.ch/t/ratio-plot/9439>\
**Category:** ROOT\
**Created:** [January 8, 2010, 5:15pm UTC](https://root-forum.cern.ch/t/ratio-plot/9439 "2010-01-08T17:15:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaksmet](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/d9b06d/32.png) [@Kaksmet](https://root-forum.cern.ch/u/Kaksmet)\
**Post date:** [January 8, 2010, 5:15pm UTC](https://root-forum.cern.ch/t/ratio-plot/9439/1 "2010-01-08T17:15:22Z")

</div>

Hello

Iam rather new to ROOT so bare with me…  
While drawing multiple histograms in one canvas I would like to also create a ratio plot just below the original histograms, is there any good way to accomplish this?

Thanks  
Tomas

---

<div class="post-metadata">

**Author:** ![brun](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/b9e5f3/32.png) [@brun](https://root-forum.cern.ch/u/brun)\
**Post date:** [January 8, 2010, 5:44pm UTC](https://root-forum.cern.ch/t/ratio-plot/9439/2 "2010-01-08T17:44:59Z")

</div>

see this example

Rene

```auto
void ratio() {
   TH1F *h1 = new TH1F("h1","test1",100,-3,3);
   h1->FillRandom("gaus",200000);
   h1->GetXaxis()->SetLabelFont(63); //font in pixels
   h1->GetXaxis()->SetLabelSize(16); //in pixels
   h1->GetYaxis()->SetLabelFont(63); //font in pixels
   h1->GetYaxis()->SetLabelSize(16); //in pixels
   TH1F *h2 = new TH1F("h2","test2",100,-3,3);
   h2->FillRandom("gaus",100000);
   TCanvas *c1 = new TCanvas("c1","example",600,700);
   TPad *pad1 = new TPad("pad1","pad1",0,0.3,1,1);
   pad1->SetBottomMargin(0);
   pad1->Draw();
   pad1->cd();
   h1->DrawCopy();
   h2->Draw("same");
   c1->cd();
   TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.3);
   pad2->SetTopMargin(0);
   pad2->Draw();
   pad2->cd();
   h1->Sumw2();
   h1->SetStats(0);
   h1->Divide(h2);
   h1->SetMarkerStyle(21);
   h1->Draw("ep");
   c1->cd();
}

```

---

<div class="post-metadata">

**Author:** ![SebastianSchmitt](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@SebastianSchmitt](https://root-forum.cern.ch/u/SebastianSchmitt)\
**Post date:** [December 4, 2011, 3:49pm UTC](https://root-forum.cern.ch/t/ratio-plot/9439/3 "2011-12-04T15:49:19Z")

</div>

Hi!

Is it possible to avoid that the 0 of the upper y axis gets truncated?

Thanks,

Sebastian

---

<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:** [December 5, 2011, 12:15pm UTC](https://root-forum.cern.ch/t/ratio-plot/9439/4 "2011-12-05T12:15:57Z")

</div>

one possible way:

```auto
void ratio() {
   TH1F *h1 = new TH1F("h1","test1",100,-3,3);
   h1->FillRandom("gaus",200000);
   h1->GetXaxis()->SetLabelFont(63); //font in pixels
   h1->GetXaxis()->SetLabelSize(16); //in pixels
   h1->GetYaxis()->SetLabelFont(63); //font in pixels
   h1->GetYaxis()->SetLabelSize(16); //in pixels
   TH1F *h2 = new TH1F("h2","test2",100,-3,3);
   h2->FillRandom("gaus",100000);
   TCanvas *c1 = new TCanvas("c1","example",600,700);
   TPad *pad1 = new TPad("pad1","pad1",0,0.3,1,1);
   pad1->SetBottomMargin(0);
   pad1->Draw();
   pad1->cd();

   TH1F *h3=h1->DrawCopy();
   h3->SetMinimum(-100);
   h2->Draw("same");
   c1->cd();
   TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.3);
   pad2->SetTopMargin(0);
   pad2->Draw();
   pad2->cd();
   h1->Sumw2();
   h1->SetStats(0);
   h1->Divide(h2);
   h1->SetMarkerStyle(21);
   h1->Draw("ep");
   c1->cd();
}

```

---

<div class="post-metadata">

**Author:** ![Jordi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@Jordi](https://root-forum.cern.ch/u/Jordi)\
**Post date:** [September 6, 2012, 3:49pm UTC](https://root-forum.cern.ch/t/ratio-plot/9439/5 "2012-09-06T15:49:52Z")

</div>

Hi,

I have a similar problem, my upper number get truncated, but in the ratio (down) plot.  
Is there a way to get the complete number in the bottom plot?

Thank you!

---

<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:** [September 6, 2012, 4:40pm UTC](https://root-forum.cern.ch/t/ratio-plot/9439/6 "2012-09-06T16:40:37Z")

</div>

[url][SetAxisRange(0.0,1.0,"Y"); is ineffective](https://root-forum.cern.ch/t/setaxisrange-0-0-1-0-y-is-ineffective/14040/4)  
[url][Palette on a TProfile2d](https://root-forum.cern.ch/t/palette-on-a-tprofile2d/14704/2)  
[url][SetRangeUser doesn't work well](https://root-forum.cern.ch/t/setrangeuser-doesnt-work-well/14774/2)

---

<div class="post-metadata">

**Author:** ![Jordi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@Jordi](https://root-forum.cern.ch/u/Jordi)\
**Post date:** [September 7, 2012, 10:41am UTC](https://root-forum.cern.ch/t/ratio-plot/9439/7 "2012-09-07T10:41:18Z")

</div>

Thank you… but my problem is not setting the axis limits, but the upper number of the axis is truncated.

---

<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:** [September 7, 2012, 11:58am UTC](https://root-forum.cern.ch/t/ratio-plot/9439/8 "2012-09-07T11:58:41Z")

</div>

I assume that the problem is in the “vertical” direction (i.e. the upper part of the number is not visible). In this case, if you change the axis maximum (or your histogram maximum), the number which is truncated will also be moved in the picture (so it will either entirely disappear or it will become entirely visible).  
Unless the problem is in the “horizontal” direction (e.g. that the left part of the number is not drawn).

---

<div class="post-metadata">

**Author:** ![Jordi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@Jordi](https://root-forum.cern.ch/u/Jordi)\
**Post date:** [September 7, 2012, 1:09pm UTC](https://root-forum.cern.ch/t/ratio-plot/9439/9 "2012-09-07T13:09:10Z")

</div>

Great! 🙂 Thank you!
