# Axis Extension for Sparse Histograms

**URL:** <https://root-forum.cern.ch/t/axis-extension-for-sparse-histograms/62844>\
**Category:** General Chat\
**Tags:** hist\
**Created:** [February 8, 2025, 12:30pm UTC](https://root-forum.cern.ch/t/axis-extension-for-sparse-histograms/62844 "2025-02-08T12:30:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![newbie2](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/b4bc9f/32.png) [@newbie2](https://root-forum.cern.ch/u/newbie2)\
**Post date:** [February 8, 2025, 12:30pm UTC](https://root-forum.cern.ch/t/axis-extension-for-sparse-histograms/62844/1 "2025-02-08T12:30:03Z")

</div>

Is it possible to extend any of the axes of a sparse histogram ?  
For example, consider the following example

```auto
void Test(){

   TRandom3 Random;

   double Min[] = {0., 0.};
   double Max[] = {1., 10.};
   int NBin[] = {100, 100};

   THnSparseD Hist("Hist", "Hist2D", 2, NBin, Min, Max);
   Hist.GetAxis(1)->SetCanExtend(true);

   for(int Iter = 0; Iter < 1000; Iter++)
     Hist.Fill(std::vector<double>{Random.Rndm(), 20*Random.Rndm()}.data());

   Hist.SaveAs("Hist.root");

}

```

The values for filling the second axis are intentionally sampled from a uniform  
distribution from the range (0, 20). Initially the axis range maximum is taken to  
be 10 but a possible extension criterion is set. However, the output histogram  
has the maximum still set at 10 and of course there are entries in the overflow  
bin.

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [February 8, 2025, 5:45pm UTC](https://root-forum.cern.ch/t/axis-extension-for-sparse-histograms/62844/2 "2025-02-08T17:45:52Z")

</div>

Hi,

Thanks for the post. Maybe I am wrong, but aren’t the dimension of the array with which you fill the histogram and the dimension of the sparse histogram not matching?

Cheers,  
Danilo

---

<div class="post-metadata">

**Author:** ![newbie2](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/b4bc9f/32.png) [@newbie2](https://root-forum.cern.ch/u/newbie2)\
**Post date:** [February 15, 2025, 7:19pm UTC](https://root-forum.cern.ch/t/axis-extension-for-sparse-histograms/62844/3 "2025-02-15T19:19:08Z")

</div>

Hi,

Can you kindly elaborate? Maybe I am missing something trivial here.  
Pardon my naivety.
