# How can I change the z-axis range of a 2d graph

**URL:** <https://root-forum.cern.ch/t/how-can-i-change-the-z-axis-range-of-a-2d-graph/53783>\
**Category:** Newbie\
**Created:** [February 25, 2023, 10:36pm UTC](https://root-forum.cern.ch/t/how-can-i-change-the-z-axis-range-of-a-2d-graph/53783 "2023-02-25T22:36:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbl1230](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/ba8739/32.png) [@mbl1230](https://root-forum.cern.ch/u/mbl1230)\
**Post date:** [February 25, 2023, 10:36pm UTC](https://root-forum.cern.ch/t/how-can-i-change-the-z-axis-range-of-a-2d-graph/53783/1 "2023-02-25T22:36:03Z")

</div>

* * *

I want to plot a number of 3d curves using TGraph2D since based on searching the forum I found that MultiGraph doesn’t work for 3d curves. I have been able to plot each curve in the same canvas, but the x/y/z plot range is fixed at the values required for the first plot and subsequent plots extend beyond those limits. I tried to change the axis range to accommodate additional plots but that didn’t change the plot. Attached is a test script that I have been using to figure out how to generate the plot. The actual data to be plotted is generated in a Monte Carlo simulation. Does anyone have any thoughts on either a way to change the axis limits or an alternative way to generate this plot?  
 ![c1](https://root-forum.cern.ch/uploads/default/original/3X/5/f/5f450a4c00c0ca362c3276380f154b0c32b0cda3.png)

```auto
#include "TGraph.h"
#include "TAxis.h"
{
  double pi=4.*atan(1.);
  auto c1 =new TCanvas("c1","Test1",0,0,600,400);
  auto g = new TGraph2D();
  double x, y, z;
  for(int n=0;n<2;n++){
    for(int k=0;k<30;k++){
      x=cos(2*pi*k/30.);
      y=sin(2*pi*k/30.);
      z = (n+1)*k/30.;
      g->SetPoint(k,x,y,z);
    }
    if(n==0){
      c1->cd();
      g->DrawClone("line""p0");
      g->GetZaxis()->SetRangeUser(0.,3.);
    }
    else
      {
	c1->cd(1);
	g->DrawClone("LINE""P0""SAME");
	g->GetZaxis()->SetRangeUser(0.,3.);
       }
  }  
}

```

_ROOT Version:_ 6-28-00  
_Platform:_ Ubuntu 22  
_Compiler:_ Not Provided

* * *

---

<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:** [February 26, 2023, 11:27am UTC](https://root-forum.cern.ch/t/how-can-i-change-the-z-axis-range-of-a-2d-graph/53783/2 "2023-02-26T11:27:57Z")

</div>

```cpp
      g->SetMinimum(0.); g->SetMaximum(3.); // before drawing
      g->DrawClone("line p0"); // the first graph (defines axes)

```

---

<div class="post-metadata">

**Author:** ![mbl1230](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/ba8739/32.png) [@mbl1230](https://root-forum.cern.ch/u/mbl1230)\
**Post date:** [February 26, 2023, 4:10pm UTC](https://root-forum.cern.ch/t/how-can-i-change-the-z-axis-range-of-a-2d-graph/53783/3 "2023-02-26T16:10:56Z")

</div>

Many thanks Wile.

![image001.jpg](https://root-forum.cern.ch/uploads/default/original/3X/2/4/2485d26919316b1d80aa60f5ca8e2cb5bc0275fe.jpeg)
