Hi there, I have TCanvas graphs I’ve made and I want to display them all on a single graph that’s been partitioned.
I’ve tried a lot of variations but basically this is the code I’ve been writting:
{
TCanvas *C = new TCanvas(“C”,“All Equilibrium Graphs”,1100,800); // This is the canvas I want to have all the graphs drawn in
C->Divide(2,2);
TFile *f1 = new TFile(“537Equilibrium.root”); // this file contains the graphs of interest
f1->ReadAll();
TCanvas *C1 = f1->Get(“c1”); //c1 is the graph I’m interested in placing on pad0 of the C canvas.
TVirtualPad *P1 = C1->GetPad(0);
C->GetPad(0) = P1;
C->GetPad(0)->Draw();
}
What am I doing wrong? Any help would be greatly appreciated! Thanks!
When you divide a canvas using C->Divide(2,2) you should use the TPad method “cd” to define in which pad you want to draw the next plot. So if “g” is the graph you want to draw simply do:
C->cd(1); // make the 1st C’s sub-pad the current one
g->Draw();
I hope this answer your question. As you do not have sent the file containing your graphs it is not possible to try your macro.
Thanks but no that doesn’t help. I tried the cd command earlier and again but it just doesn’t seem to draw the graph.
Here’s the file, 537Equilibrium.root (14 KB)
I ran your code snippet and it pops up a new window with the proper graph but the divided canvas is still empty. Did you get it to draw in the divided canvas?
Thanks for investigating!
I guess what I’m after is a simple work-around to the problem. I went with using the cd command then Draw and when that initially failed to work I thought about accessing the pads directly, which should in theory be possible. Can you get my initial code to work in the new version? I get a “wrong l-value” error.
Thanks for the help, but it still isn’t working. I get the graph in a different pop-up window and not in the intended split canvas. What draw option in TGraphErrors would be proper? Because I can re-generate the original graph easily. Here’s the code that produces the TGraph of interest.
The draw options I’m using are ALP, LP and LP. Equilibrium.C (3.11 KB)