# Draw two TH2 on the same canvas with different Yaxis

**URL:** <https://root-forum.cern.ch/t/draw-two-th2-on-the-same-canvas-with-different-yaxis/40285>\
**Category:** Newbie\
**Created:** [July 7, 2020, 8:47am UTC](https://root-forum.cern.ch/t/draw-two-th2-on-the-same-canvas-with-different-yaxis/40285 "2020-07-07T08:47:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aciarma](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@aciarma](https://root-forum.cern.ch/u/aciarma)\
**Post date:** [July 7, 2020, 8:47am UTC](https://root-forum.cern.ch/t/draw-two-th2-on-the-same-canvas-with-different-yaxis/40285/1 "2020-07-07T08:47:59Z")

</div>

Hi, I am trying to draw on the same canvas two TH2 where the X-axis is in common while the Y-axis is different for the two (and I have no interest on the Z-axis).

I do know how to draw a new TGaxis on the top/right side, but I do not know how to scale accordingly the second plot I draw, it gets plotted on the “first axis”.

The code I am using now is:

```auto
TCanvas *c1 = new TCanvas("c1");

  line->Draw("dx:pos","","line"); //draw just to get dxmax and dxmin, it gets overwritten
  double dxmax = gPad->GetUymax(); //
  double dxmin = gPad->GetUymin(); // 

  line->SetLineColor(kRed);
  line->Draw("betx:pos","","line");
  line->SetLineColor(kGreen);
  line->SetLineStyle(1);
  line->Draw("dx:pos","","linesame");
  TGaxis *axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),gPad->GetUxmax(), gPad->GetUymax(),dxmin,dxmax,510,"+L");
  axis->Draw();
  c1->SaveAs("c1.eps");

```

Thank you for your help

Andrea

---

<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:** [July 7, 2020, 9:16am UTC](https://root-forum.cern.ch/t/draw-two-th2-on-the-same-canvas-with-different-yaxis/40285/2 "2020-07-07T09:16:31Z")

</div>

You will need to make an overlay pad like in this example:  
[https://root.cern/doc/master/transpad\_8C.html](https://root.cern/doc/master/transpad_8C.html)
