TGraph->Draw("[same-if-possible]")

Hi,

I find myself constantly doing something like:

if(the previous graph was drawn) graph->Draw("APSame"); else if (the previous graph was not drawn) graph->Draw("AP");

Is there a draw option I am overlooking that encapsulates this behavior? To draw with the same option if possible, but if it’s not possible, to just draw normally?

Thanks,

Joe

the code should be:

if(the previous graph was drawn) graph->Draw("P");
else if (the previous graph was not drawn) graph->Draw("AP");

But what you need is in fact:
root.cern.ch/root/html/TMultiGraph.html

Excellent, thanks for reminding me to use multigraph, very useful.

I have another question on this, which is I sometimes would like to do the same thing, but with TGraph2D instead of TGraph (not a mix of both, just all TGraph2D, clearly mixing would lead to some issues). Is there a similar container class for these as well? I did not see a TMultiGraph2D.

Or would a TObjArray of TGraph2D’s be better / easier?

Thanks,

Joe

p.s.

[quote=“couet”]the code should be:

if(the previous graph was drawn) graph->Draw("P");
else if (the previous graph was not drawn) graph->Draw("AP");

Although I didn’t make it obvious, my intent is to draw both graphs simultaneously on the same set of axes if they both exist, while if only one exists to only draw one of them. In this case I think “ap” (if this graph is the first one) and “psame” (if this graph is the second one) are the correct options. Either way multigraph is easier (unless it doesn’t exist for TGraph2D…)

There is no TMultigraph2D.
Use the option SAME as shown here: root.cern.ch/root/html/TGraph2D.html