# 3D Histogram - Changing the Physical Length of an Axis

**URL:** <https://root-forum.cern.ch/t/3d-histogram-changing-the-physical-length-of-an-axis/35327>\
**Category:** Newbie\
**Created:** [July 24, 2019, 8:01pm UTC](https://root-forum.cern.ch/t/3d-histogram-changing-the-physical-length-of-an-axis/35327 "2019-07-24T20:01:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ethan\_Nguyen](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@Ethan\_Nguyen](https://root-forum.cern.ch/u/Ethan_Nguyen)\
**Post date:** [July 24, 2019, 8:01pm UTC](https://root-forum.cern.ch/t/3d-histogram-changing-the-physical-length-of-an-axis/35327/1 "2019-07-24T20:01:41Z")

</div>

Hi,

I’m working with 3D histograms. Is it possible to change the physical length of the x-axis?

Right now, no matter the ranges for x,y,z, the axis length is identical.

Thanks!

```auto
void sandbox()
{
   //Create and fill TH3.
   const UInt_t nX = 200;
   const Double_t xMin = 0, xMax = 200, xStep = (xMax - xMin) / (nX - 1);
   const UInt_t nY = 20;
   const Double_t yMin = 0, yMax = 20., yStep = (yMax - yMin) / (nY - 1);
   const UInt_t nZ = 20;
   const Double_t zMin = 0., zMax = 20., zStep = (zMax - zMin) / (nZ - 1)
     ;
   
   TH3F *hist = new TH3F("glvoxel", "glvoxel", 200, 0., 200., 20, 0., 20., 20, 0., 20.);

   //Fill the histogram to create a "sphere".
   for (UInt_t i = 0; i < nZ; ++i) {
      const Double_t z = zMin + i * zStep;
      for (UInt_t j = 0; j < nY; ++j) {
         const Double_t y = yMin + j * yStep;
         for (UInt_t k = 0; k < nX; ++k) {
            const Double_t x = xMin + k * xStep;
            const Double_t val = 1. - (x * x + y * y + z * z);
            hist->SetBinContent(k + 1, j + 1, i + 1, val*100);
         }
      }
   }
   gStyle->SetCanvasPreferGL(1);
   hist->Draw("glcol");
}

```

 ![53%20PM](https://root-forum.cern.ch/uploads/default/original/3X/3/8/3881b9f30e9403374a8549d40aebea42cb25c7bd.jpeg)

---

<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 25, 2019, 7:40am UTC](https://root-forum.cern.ch/t/3d-histogram-changing-the-physical-length-of-an-axis/35327/2 "2019-07-25T07:40:38Z")

</div>

> [@Ethan\_Nguyen](#):
>
> Right now, no matter the ranges for x,y,z, the axis length is identical.

Yes, it is implemented this way. you will always get a cube.
