# Histogram bins getting connected

**URL:** <https://root-forum.cern.ch/t/histogram-bins-getting-connected/62962>\
**Category:** Newbie\
**Created:** [February 17, 2025, 12:35pm UTC](https://root-forum.cern.ch/t/histogram-bins-getting-connected/62962 "2025-02-17T12:35:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![phylmath](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/phylmath/32/38400_2.png) [@phylmath](https://root-forum.cern.ch/u/phylmath)\
**Post date:** [February 17, 2025, 12:35pm UTC](https://root-forum.cern.ch/t/histogram-bins-getting-connected/62962/1 "2025-02-17T12:35:20Z")

</div>

_ROOT Version:_ 6.32.04  
_Platform:_ WSL2 Ubuntu

Hello! I am attempting to draw a histogram, however ROOT connects the individual markers. I am guessing it has something to do with the binning but cannot find a solution.

Appreciate any input. Thanks in advance!

Code below.

```auto
// Define histogram
TH1D *hist_exp = new TH1D("hist_exp", " ", 28, 1, 57);
// Import data
ifstream infile_exp("xx.txt");
// Read through txt
while (getline(infile_exp, line)) {
	// Set reading order
	istringstream iss(line);
	iss >> Nch >> Prb >> Err_Nch >> Err_Prb;
	// Populate histogram
	hist_exp->SetBinContent(hist_exp->FindBin(Nch), Prb);
	// Populate error bar
	hist_exp->SetBinError(hist_exp->FindBin(Nch), Err_Prb);
}
// Close file
infile_exp.close();
// Normalise probability
hist_exp->Scale(1.0/hist_exp->Integral());
// Create canvas
TCanvas* c_nch = new TCanvas(c_nch, Charged hadron multiplicity distributions, 800, 600);
// Draw histogram
hist_exp->Draw("c_nch");

```

Below, the resulting plot (left) and the txt file (right).

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/e/1/e11e19f325b299a61692bd1fea9134423f621050.png) ![image](https://root-forum.cern.ch/uploads/default/original/3X/6/5/6588572b4feccf3d64f1abe949e726cfdf1dcf72.png)

---

<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:** [February 17, 2025, 1:11pm UTC](https://root-forum.cern.ch/t/histogram-bins-getting-connected/62962/2 "2025-02-17T13:11:49Z")

</div>

try:

```auto
hist_exp->Draw("P");

```

---

<div class="post-metadata">

**Author:** ![phylmath](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/phylmath/32/38400_2.png) [@phylmath](https://root-forum.cern.ch/u/phylmath)\
**Post date:** [February 17, 2025, 1:25pm UTC](https://root-forum.cern.ch/t/histogram-bins-getting-connected/62962/3 "2025-02-17T13:25:26Z")

</div>

That solved it, thank you! Following on this, how can I specify the canvas to draw the histogram to (“n\_ch”) _ **and** _ specify this “P” parameter?

---

<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:** [February 17, 2025, 1:53pm UTC](https://root-forum.cern.ch/t/histogram-bins-getting-connected/62962/4 "2025-02-17T13:53:57Z")

</div>

```auto
c_nch->cd();
hist_exp->Draw("P");

```

---

<div class="post-metadata">

**Author:** ![phylmath](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/phylmath/32/38400_2.png) [@phylmath](https://root-forum.cern.ch/u/phylmath)\
**Post date:** [February 17, 2025, 1:54pm UTC](https://root-forum.cern.ch/t/histogram-bins-getting-connected/62962/5 "2025-02-17T13:54:13Z")

</div>

Thanks again!
