TGraph sets nonzero points to zero

Hello,

I am trying to fill a TGraph object. However, every time I try and pass a point to the TGraph, it gets set to zero or otherwise refuses to be plotted. The code:

TGraph2D* t6_11_plot = new TGraph2D();
[...]
if(e.t_drift >= 6 && e.t_drift <= 11) {
	t6_11_plot->SetPoint(eventnumber, e.x, e.y, e.t_drift);
}

Finally I try and write the relevant graph to a canvas for viewing with TBrowser.

TCanvas* canvas15 = new TCanvas("Drift time2", "Drift time2");
canvas15->cd();
t6_11_plot->Draw("LEGO2");
t6_11_plot->SetTitle("Drift time for 6 < t < 11");
canvas15->Write("X vs Y vs Drift time 3");

Which gives me the result


I am aboslutely certain that the relevant points are not zero. So why aren’t they plotting?

Try:
t6_11_plot->SetPoint(t6_11_plot->GetN(), e.x, e.y, e.t_drift);

1 Like

[quote=“Pepe Le Pew”]Try:
t6_11_plot->SetPoint(t6_11_plot->GetN(), e.x, e.y, e.t_drift);[/quote]

Thank so you much works fine now.