# Histogram from txt FIle

**URL:** <https://root-forum.cern.ch/t/histogram-from-txt-file/45528>\
**Category:** Newbie\
**Created:** [June 24, 2021, 2:33am UTC](https://root-forum.cern.ch/t/histogram-from-txt-file/45528 "2021-06-24T02:33:26Z")\
**Posts on this page:** 4\
**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:** [June 24, 2021, 2:33am UTC](https://root-forum.cern.ch/t/histogram-from-txt-file/45528/1 "2021-06-24T02:33:26Z")

</div>

Hello!

I have a two column of data: Energy and Flux. I am trying to draw histogram with energy in x-axis and flux in y-axis. However, I am not getting the desired result as I am only getting empty canvas. Here is my code:

```auto
{
        TFile *f = new TFile("data.root", "RECREATE");
        TNtuple *t= new TNtuple("Flux_data", "Data from DUNE", "Energy:Flux");
        t->ReadFile("data.txt");

        TH1F h("Flux_hist", "Energy vs. Flux; Energy; Flux", 25, 0, 50);
        t->Draw("Flux>>Flux_Hist");
        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:** [June 24, 2021, 6:38am UTC](https://root-forum.cern.ch/t/histogram-from-txt-file/45528/2 "2021-06-24T06:38:16Z")

</div>

May be try:

```auto
        auto h = TH1F("Flux_hist", "Energy vs. Flux; Energy; Flux", 25, 0, 50);
        t->Draw("Flux>>Flux_Hist");
        h->Write();

```

---

<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:** [June 24, 2021, 6:12pm UTC](https://root-forum.cern.ch/t/histogram-from-txt-file/45528/3 "2021-06-24T18:12:48Z")

</div>

This is giving me Flux value in x-axis and frequency in y-axis. I want Energy value in x-axis and associated flux value in y-axis. Please let me know how I can do this. Thanks.

---

<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:** [June 24, 2021, 7:12pm UTC](https://root-forum.cern.ch/t/histogram-from-txt-file/45528/6 "2021-06-24T19:12:38Z")

</div>

Try this: `t->Draw("Flux:Energy"); // a TGraph`  
and / or that: `t->Draw("Flux:Energy>>Flux_vs_Energy", "", "COLZ"); // a TH2F`
