How to go back and add to a TCanvas

Normally, one defines a canvas and immediately adds everything relevant to it. You don’t need to access a canvas after you’ve moved on to other canvases.
However, I’m writing a program that takes an array of data files, and iterates through them, adding their contents to the graphs. So I need to be able to add to previous canvases.
I’m looking for something like, gROOT->GetCanvas(c1);, so that if I do graph1->Draw("same"); then graph1 ends up on the canvas c1.


ROOT Version: 6.10/04
Platform: Ubuntu 18.04 on Windows
Compiler: Cling


c1->cd(); is what you want.

1 Like

Graphs do NOT have the “same” drawing option (it is NOT needed).

Since there’s no “same” option for graphs, is there another way I can add a new graph to the canvas?

Just Draw().

$ root
root [0] TGraph g1
(TGraph &) Name:  Title: 
root [1] g1.SetPoint(0, 1, 1)
root [2] TGraph g2
(TGraph &) Name:  Title: 
root [3] g2.SetPoint(0, 2, 2)
root [4] g1.Draw("a *")
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [5] g2.Draw("*")
1 Like

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