how does one assign data to be plotted in several canvases. Say in this simple for loop
int filter = 20;
Double_t x,y;
TCanvas *c1 = new TCanvas();
TCanvas *c2 = new TCanvas();
for(int i = 0; i<someImax; i++) {
x = 10.5*i;
TGraph *g = new TGraph();
TPolyLine3D *polyLine = new TPolyLine3D(filter);
for (int j=0; j<someJmax; j++) {
y =5.5*j;
g->SetPoint(i, x,y)
polyLine->SetPoint(i, i, x,y);
}
//then i want to draw g in c1 and polyLine in c2. Do i c1->Update() and c2->Update() each time? How do I switch from one canvas to another inside the loop?
g->Draw("AL");
polyLine->Draw();
}
You need to “SomeCanvas->cd(SomePadNumber);” in order to draw something in a particular pad of a particular canvas (“SomePadNumber” = 0 if you don’t have any sub-pads, of course).
Thanks Wile. In this piece of code for instance, TGraph *g was drawn perfectly well in c1, TH3F *h3eff was drawn on c2, however with polyLine->Draw() in c2, nothing happened.
See, for example, the TPolyLine3D class description for an example how to draw it.
Note: the “axes-ranges” of your “polyLine” must be similar to the “axes-ranges” of your “h3eff” (which actually creates the “view” when drawn), otherwise you will not see your “polyLine” (it will be drawn “outside” of your canvas).
Note also: in your “M1: … goto M1;” loop you create “TGraph” and “TPolyLine3D” objects but you never delete them.
TCanvas *c1 = new TCanvas(“c1”);
c1 = c1; // get rid of the warning: unused variable ‘c1’
TH3F h3 = new TH3F(“h3”, “TH3 and TPolyLine3D”,
10, -2, 2, 10, -2, 2, 10, 0, 4);
for (i = 0; i < 10000; i++) {
gRandom->Rannor(x, y);
z = xx + y*y;
h3->Fill(x, y, z);
} // for (i …
for (j = 0; j < 100; j++) { #if 0 /* 0 or 1 /
delete l; // delete the “previous” one #endif / 0 or 1 */
l = new TPolyLine3D(n);
for (i = 0; i < n; i++) {
x = 2.0 * gRandom->Rndm();
y = 2.0 * gRandom->Rndm();
z = 2.0 * gRandom->Rndm();
l->SetPoint(i, x, y, z);
} // for (i …
If I follow the example (for-loop inside a for loop) as you propose, i encounter busyflag error as far as my needs , well described in the link above…
for (j = 0; j < 100; j++) {
l = new TPolyLine3D(n);
for (i = 0; i < n; i++) {
x = 2.0 * gRandom->Rndm();
y = 2.0 * gRandom->Rndm();
z = 2.0 * gRandom->Rndm();
l->SetPoint(i, x, y, z);
}
l->Draw();