# Histograms as curves or lines

**URL:** <https://root-forum.cern.ch/t/histograms-as-curves-or-lines/58977>\
**Category:** Newbie\
**Created:** [April 12, 2024, 7:48pm UTC](https://root-forum.cern.ch/t/histograms-as-curves-or-lines/58977 "2024-04-12T19:48:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trinayan\_Saikia](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/trinayan_saikia/32/36207_2.png) [@Trinayan\_Saikia](https://root-forum.cern.ch/u/Trinayan_Saikia)\
**Post date:** [April 12, 2024, 7:48pm UTC](https://root-forum.cern.ch/t/histograms-as-curves-or-lines/58977/1 "2024-04-12T19:48:36Z")

</div>

Why there are vertical lines along the data points in the diagram. can,t these four histograms be shown as dark lines?

```auto
void Hist1_Thdata() {

    THStack *hs = new THStack("hs", "Stacked data for various energies;energy(mev);cross section(b/mev)");

    const int n = 648;
    double en[n], cs[n];

    FILE *thfile = fopen("thor.txt", "r");

    TH1D *h1 = new TH1D("h1", "2.03 MeV", 174, 0.04, 17.6);
    h1->SetStats(0);
    h1->SetLineColor(kBlue);
    h1->Sumw2();

    TH1D *h2 = new TH1D("h2", "4.25 MeV", 334, 0.04, 17.6);
    h2->SetStats(0);
    h2->SetMarkerStyle(11);
    h2->SetMarkerSize(0.2);
    h2->SetMarkerColor(kGreen);
    h2->SetLineColor(kGreen);
    h2->Sumw2();

    TH1D *h3 = new TH1D("h3", "6.1 MeV", 494, 0.04, 17.6);
    h3->SetStats(0);
    h3->SetMarkerStyle(31);
    h3->SetMarkerSize(0.2);
    h3->SetMarkerColor(kRed);
    h3->SetLineColor(kRed);
    h3->Sumw2();
    
    
    TH1D *h4 = new TH1D("h4", "14.5 MeV", 648, 0.04, 17.6);
    h4->SetStats(0);
    h4->SetMarkerStyle(41);
    h4->SetMarkerSize(0.2);
    h4->SetMarkerColor(kBlack);
    h4->SetLineColor(kBlack);
    h4->Sumw2();

    for (int t = 0; t < n; t++) {
        fscanf(thfile, "%lf %lf \n", &en[t], &cs[t]);

        if (t < 174)
            h1->Fill(en[t], cs[t]);
        else if (t < 334)
            h2->Fill(en[t], cs[t]);
        else if (t < 494)
            h3->Fill(en[t], cs[t]);
        else
            h4->Fill(en[t], cs[t]);
    }

    fclose(thfile);
    
        TCanvas *c = new TCanvas("c", "90-TH-232(N,X)O-NN-1,,DE", 800, 500);
    gPad->SetLogx();
    gPad->SetLogy();
    c->SetGridx();
    c->SetGridy();
    c->SetTickx(1);
    c->SetTicky(1);
    c->SetFrameFillColor(0);
    c->SetFrameFillStyle(3003);
    c->SetFrameLineColor(5);
    c->SetFrameLineWidth(2);
    c->SetFrameBorderMode(0);
    c->SetFrameFillStyle(3003);
    c->SetFrameLineColor(5);
    c->SetFrameLineWidth(2);
    c->SetFrameBorderMode(0);
    c->Draw();

    hs->Add(h1);
    hs->Add(h2);
    hs->Add(h3);
    hs->Add(h4);
    hs->Draw("nostack");
    //hs->Draw("L");
    hs->GetXaxis()->CenterTitle(1);
    hs->GetYaxis()->CenterTitle(1);
    
    TLegend *legend = new TLegend(0.8, 0.85, 0.9, 0.9);
    legend->AddEntry(h1, "2.03 MeV", "l");
    legend->AddEntry(h2, "4.25 MeV", "l");
    legend->AddEntry(h3, "6.1 MeV", "l");
    legend->AddEntry(h4, "14.05 MeV", "l");
    legend->Draw();
    
    c->Modified();
    c->Update();
    

}

```

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [April 13, 2024, 5:46am UTC](https://root-forum.cern.ch/t/histograms-as-curves-or-lines/58977/2 "2024-04-13T05:46:55Z")

</div>

> [@Trinayan\_Saikia](#):
>
> ` h1->Sumw2();`

When the histograms have errors, they are drawn. To avoid drawing the errors you can add the “hist” option to Draw:

```auto
    hs->Draw("nostack hist");

```
