# Histogram draw (draw a simple line connecting all histogram bin points)

**URL:** <https://root-forum.cern.ch/t/histogram-draw-draw-a-simple-line-connecting-all-histogram-bin-points/41744>\
**Category:** Newbie\
**Created:** [October 7, 2020, 3:58am UTC](https://root-forum.cern.ch/t/histogram-draw-draw-a-simple-line-connecting-all-histogram-bin-points/41744 "2020-10-07T03:58:20Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![NewRootUser](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/9fc348/32.png) [@NewRootUser](https://root-forum.cern.ch/u/NewRootUser)\
**Post date:** [October 14, 2020, 9:20am UTC](https://root-forum.cern.ch/t/histogram-draw-draw-a-simple-line-connecting-all-histogram-bin-points/41744/22 "2020-10-14T09:20:48Z")

</div>

c1.root [c1.root](https://root-forum.cern.ch/uploads/short-url/pN6xWyBjNT04DvUnKrpe1LXypD1.root) (14.5 KB) this has only one value.  
[2.root](https://root-forum.cern.ch/uploads/short-url/aArejxOURl1g8ycGEyWexh8cwsi.root) (44.2 KB) and [3.root](https://root-forum.cern.ch/uploads/short-url/8H43Ra8svavGgsuDsbPi6NNyGez.root) (43.9 KB) (h16) both have same axis range and used here as dummy. So if you want to try then you can use any of them in macro file.

---

<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:** [October 14, 2020, 1:35pm UTC](https://root-forum.cern.ch/t/histogram-draw-draw-a-simple-line-connecting-all-histogram-bin-points/41744/23 "2020-10-14T13:35:11Z")

</div>

When i run you macro I get this picture,  
Which is correct seems to me… what’s wrong ?

 ![Screenshot 2020-10-14 at 15.33.28](https://root-forum.cern.ch/uploads/default/original/3X/7/6/764cbc082a64bca5f9f09c119eda1b013f923dad.jpeg)

---

<div class="post-metadata">

**Author:** ![NewRootUser](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/9fc348/32.png) [@NewRootUser](https://root-forum.cern.ch/u/NewRootUser)\
**Post date:** [October 14, 2020, 2:35pm UTC](https://root-forum.cern.ch/t/histogram-draw-draw-a-simple-line-connecting-all-histogram-bin-points/41744/24 "2020-10-14T14:35:16Z")

</div>

Nothing is wrong with this but I want to get x-axis range x=1-5 which is x=5-6 right now.  
In my macro range is defined but as c1.root has an only single value corresponding to x=5 so its drawing only for x=5-6.

g1-\>GetXaxis()-\>SetRangeUser(0,6);

---

<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:** [October 14, 2020, 2:50pm UTC](https://root-forum.cern.ch/t/histogram-draw-draw-a-simple-line-connecting-all-histogram-bin-points/41744/25 "2020-10-14T14:50:41Z")

</div>

```auto
{
   TFile *f1 = TFile::Open("c1.root");
   TCanvas *c = (TCanvas *)f1->Get("c1");
   TGraphErrors *g1 = (TGraphErrors *)c->GetListOfPrimitives()->FindObject("Graph");
   c->Close();
   g1->GetXaxis()->SetLimits(1,5);
   g1->GetYaxis()->SetRangeUser(1,1000);

   g1->SetMarkerStyle(22);
   g1->SetMarkerSize(2);
   g1->SetLineColor(2);
   g1->SetLineWidth(3);
   g1->SetLineStyle(9);
   g1->Draw("");
   g1->GetXaxis()->SetNdivisions(509);

   TFile *f2 = TFile::Open("3.root");
   TH1D* h1 = (TH1D*)f2->Get("h16");
   h1->SetLineStyle(9);
   h1->SetMarkerStyle(21);
   h1->SetMarkerSize(2);
   h1->SetLineColor(9);
   h1->SetLineWidth(3);
   h1->Draw("HIST L P SAME");

   auto leg = new TLegend(0.51,0.69,0.9,0.9);
   leg->SetHeader("S");
   leg->AddEntry(g1,"1","l p");
   leg->AddEntry(h1, "2","a p l");
   leg->Draw();
}

```

 ![Screenshot 2020-10-14 at 16.50.23](https://root-forum.cern.ch/uploads/default/original/3X/4/0/40b80c7376d4a6383390c93ebfdd7a8713b2f564.jpeg)

---

<div class="post-metadata">

**Author:** ![NewRootUser](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/9fc348/32.png) [@NewRootUser](https://root-forum.cern.ch/u/NewRootUser)\
**Post date:** [October 14, 2020, 6:02pm UTC](https://root-forum.cern.ch/t/histogram-draw-draw-a-simple-line-connecting-all-histogram-bin-points/41744/26 "2020-10-14T18:02:26Z")

</div>

Thank you so much !! @couet😊

[Previous page](https://root-forum.cern.ch/t/histogram-draw-draw-a-simple-line-connecting-all-histogram-bin-points/41744.md?page=1)
