Histogram bins getting connected

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.

// 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).

try:

hist_exp->Draw("P");

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?

c_nch->cd();
hist_exp->Draw("P");
1 Like

Thanks again!

1 Like