# Splitting the Y axis to accomodate two histograms?

**URL:** <https://root-forum.cern.ch/t/splitting-the-y-axis-to-accomodate-two-histograms/57173>\
**Category:** Newbie\
**Created:** [November 20, 2023, 11:57am UTC](https://root-forum.cern.ch/t/splitting-the-y-axis-to-accomodate-two-histograms/57173 "2023-11-20T11:57:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [November 20, 2023, 11:57am UTC](https://root-forum.cern.ch/t/splitting-the-y-axis-to-accomodate-two-histograms/57173/1 "2023-11-20T11:57:38Z")

</div>

Hello people.

I am trying to “split” the Y axis by creating two different pads and placing them end to end. Here is the plot.

 ![brokenaxis_issue](https://root-forum.cern.ch/uploads/default/original/3X/5/d/5d270ae14b353ba92a0c1d284cbd12988868cc42.png)

I modified my code from BrokenAxis() shared by @couet in the “Remove some axis in a TPad” thread.

It works well. However, it would be great if the Y axis in the top pad starts from after where the Y axis In the below plot ends to make it look more “continuous.” I am trying to use the SetUserRange() method, but it does not cause any change in the axis range.

Can someone please suggest how to overcome this?

```auto
   [code]

   TCanvas *c = new TCanvas("c", "c",700,900);          

   TPad *p1 = new TPad("p1","p1",0.1,0.5,0.9,0.901); 
   p1->SetBottomMargin(0.);            
   p1->SetBorderMode(0);
   p1->Draw();

   TPad *p2 = new TPad("p2","p2",0.1,0.1,0.9,0.501);
   p2->SetTopMargin(0.);   
   p2->SetBorderMode(0);
   p2->Draw();
   
   // Create a histogram for the values we read.
   auto myHist = new TH1F("h1","",1000,0,1600);
   myHist->SetXTitle("E_{#gamma} [keV]");
   myHist->SetYTitle("Counts"); 

   [code]
	   myHist->Fill(1000*(*myPx));
        
   }
   p1->cd();
   myHist->SetLineColor(kBlack);
   myHist->Draw();
   p1->SetLogy(); 
   
[code]

   // Create a histogram for the values we read.
   auto myHist2 = new TH1F("h2","",1000,0,1600);
   myHist2->SetXTitle("E_{#gamma} [keV]");
   myHist2->SetYTitle("Counts"); 
[code]

    	  myHist2->Fill(*myPx2*1000);
[code]
   
   p2->cd();
   myHist2->SetLineColor(kRed);
   myHist2->Draw("same"); 
   p2->SetLogy();
   
    c->cd();
   TPad *b = new TPad("b","b",0.1,0.46,0.8199,0.54);
   b->SetBorderMode(0);
   b->Draw();
   b->cd();
   TLine *line = new TLine(0.11,0,0.1105677,0.399656);
   line->Draw();
   line = new TLine(0.1105677,0.5860092,0.11,1);
   line->Draw();
   line = new TLine(0.076639,0.5143349,0.1524797,0.6863532);
   line->Draw();
   line = new TLine(0.076639,0.3423165,0.1524797,0.5143349);
   line->Draw();
}

```

Please let me know for further clarifications from my side.  
Thanks a lot

---

<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:** [November 20, 2023, 12:29pm UTC](https://root-forum.cern.ch/t/splitting-the-y-axis-to-accomodate-two-histograms/57173/2 "2023-11-20T12:29:12Z")

</div>

Welcome to the ROOT forum.

Do you have a image showing what you what to achieve ? Seems to me if the top axis starts from where the bottom one ends it means you have only on axis …

---

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [November 20, 2023, 12:54pm UTC](https://root-forum.cern.ch/t/splitting-the-y-axis-to-accomodate-two-histograms/57173/3 "2023-11-20T12:54:28Z")

</div>

Thanks for the prompt reply.

I am trying to do something like below, except I have two histograms.  
 ![broken_demo](https://root-forum.cern.ch/uploads/default/original/3X/3/d/3d6376406556b8915f9b430cd82384469eb6660d.png)

In the plot shared earlier, the top axis starts from around 10^3 while the bottom ends at 10^4. I am trying to make the top axis start from after(not exactly where it ends) 10^3.

The issue is when I plot with only one axis.

 ![oneaxis](https://root-forum.cern.ch/uploads/default/original/3X/2/8/28424e988277dd730816ae8bc9e467cb7293c873.png)  
The red histogram is getting compressed, and I cannot see, for example, the dip at around 1400 keV.  
Is there a more efficient way to overcome this issue without splitting axes?

Thanks a lot !

---

<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:** [November 20, 2023, 12:57pm UTC](https://root-forum.cern.ch/t/splitting-the-y-axis-to-accomodate-two-histograms/57173/4 "2023-11-20T12:57:20Z")

</div>

> [@utkarsh-2000](#):
>
> I am trying to make the top axis start from after(not exactly where it ends) 10^3.

```auto
htop->SetMinimum(1000.);

```

---

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [November 20, 2023, 1:43pm UTC](https://root-forum.cern.ch/t/splitting-the-y-axis-to-accomodate-two-histograms/57173/5 "2023-11-20T13:43:22Z")

</div>

Thanks for he help.

On a side note, can you shed some light why SetRangeUser() is not a valid for this case ?

---

<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:** [November 20, 2023, 1:44pm UTC](https://root-forum.cern.ch/t/splitting-the-y-axis-to-accomodate-two-histograms/57173/6 "2023-11-20T13:44:54Z")

</div>

[https://root-forum.cern.ch/t/how-to-set-ranges-on-axis/](https://root-forum.cern.ch/t/how-to-set-ranges-on-axis/)
