Plot in a class methods?

Hi, I have a created a class and in one of its methods I draw a plot in this way:

	TCanvas* cPR = new TCanvas("cPR", "P(R)", 200, 10, 600, 400);
	cPR->SetFillColor(0);
	cPR->cd();
	TGraph* gPR = new TGraph(500,  asse, conteggio);
	gPR->SetMarkerSize(0.6);
	gPR->SetMarkerStyle(21);
	gPR->SetTitle("");
	gPR->GetXaxis()->SetTitle("Periodo");
	gPR->GetYaxis()->SetTitle("Ratio");
	gPR->Draw("AP");

But if I call the method two times root will draw only one graph because the second one has the same name. How can I do to draw both of the graphs?

Try:

// ...
TString o = "P"; // graph point markers only
TCanvas *c = ((TCanvas *)(gROOT->GetListOfCanvases()->FindObject("cPR")));
if (!c) {
  c = new TCanvas("cPR", "P(R)", 200, 10, 600, 400);
  o += "A"; // a new canvas needs new graph axes, too
}
// ...
gPR->SetTitle(";Periodo;Ratio");
gPR->Draw(o);
// ...

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.