# Setting Y axis Range in Histogram

**URL:** <https://root-forum.cern.ch/t/setting-y-axis-range-in-histogram/45760>\
**Category:** Newbie\
**Created:** [July 8, 2021, 9:52pm UTC](https://root-forum.cern.ch/t/setting-y-axis-range-in-histogram/45760 "2021-07-08T21:52:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheScientist](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/82dd89/32.png) [@TheScientist](https://root-forum.cern.ch/u/TheScientist)\
**Post date:** [July 8, 2021, 9:52pm UTC](https://root-forum.cern.ch/t/setting-y-axis-range-in-histogram/45760/1 "2021-07-08T21:52:46Z")

</div>

I am trying to set Y-axis range limit as my histogram is not fully shown in the canvas. Here is my code. Please let me know how to set the y axis range correctly. Thank you.

```auto
{
        TFile *f = new TFile("data.root", "RECREATE");
        ifstream input;
        input.open("nrhf-data.txt");

        TH1D* h = new TH1D("Flux_hist", "#nu_{mu} : Energy vs. Flux; Energy (GeV); Flux", 5, 0, 6);
        unsigned int i;
        float x; // energy
        float y; // flux

        while( !input.eof() )
        {
                input >> x >> y;
                cout << x << ", " << y << endl;
                i = h->FindBin(x);
                h->SetBinContent(i, y);
        }   
        h->GetYaxis->SetRange(0,0.0000412);
        h->Write();
        f->Close();
}

```

---

<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 9, 2021, 5:32am UTC](https://root-forum.cern.ch/t/setting-y-axis-range-in-histogram/45760/2 "2021-07-09T05:32:57Z")

</div>

See the last example here: [How to set ranges on axis?](https://root-forum.cern.ch/t/how-to-set-ranges-on-axis/28254)
