when I try to do this
for …:
…
TCanvas()
…
#draw something
it makes a new TCanvas but it overwrites the previous one.
How can I actually make a new TCanvas without overwriting the previous one?
Thanks.
Andrew
when I try to do this
for …:
…
TCanvas()
…
#draw something
it makes a new TCanvas but it overwrites the previous one.
How can I actually make a new TCanvas without overwriting the previous one?
Thanks.
Andrew
Set another names when creating them (i.e. each canvas, that you want to have, needs a “distinct” name, the default one is usually named “c1”).
{
TCanvas * c1 = new TCanvas("c1", "c1",200,0,200,200);
c1->DrawFrame(0.,0.,1.,1.);
TCanvas * c2 = new TCanvas("c2", "c2",200,250,200,200);
c2->DrawFrame(0.,0.,1.,1.);
TCanvas * c3 = new TCanvas("c3", "c3",200,500,200,200);
c3->DrawFrame(0.,0.,1.,1.);
TCanvas * c4 = new TCanvas("c4", "c4",200,750,200,200);
c4->DrawFrame(0.,0.,1.,1.);
}
This is how I do it:
canvases = []
for i,foo in enumerate(iterable):
c = ROOT.TCanvas("c%d" % i)
c.cd()
canvases.append(c)
# Now draw on the canvas
You can also use a dict with string labels or whatever you want. I store the canvases in a list/dict or some kind of Python container so that I have a “handle” on them later (e.g. I can save them or close them in a loop). The “c%d” % i is a text formatting string that will call the canvases c1,c2,c3,c4… without having to type all that manually.
Jean-François