Divided canvas in loop

Hello :slight_smile:

Why do I get 12 canvas with the same plot in this case?

c1->Divide(3,4);
TH1D * projh2Y;

for(i=1; i<9; i++){
  c1->cd(i);
  gPad->SetLogy();
  gStyle->SetOptFit(1111111);
  p = h1->ProjectionY("", i+1, i+1);
  p->Draw();
}

where h1 is a TH2F histogram.

All the divisions have the same projection of h1.

Hi,
itโ€™s really not clear to me what you are trying to achieve and what the question is :sweat_smile:
Could you elaborate a bit more?

You are filling 9 TPads a histogram projection, out of 12 TPads in which you have divided your canvas. Do you want to draw on 9 different canvases instead?

I am triyng to draw nine different projections of h1 in the canvas c1. Each projection in a different pad of the divided canvas. But root is drawing the same projection (ProjectionY("", 9, 9)) in all the pads. I want to do:

c1->cd(1);
p = h1->ProjectionY("", 2, 2);
p->Draw();

c2->cd(2);
p = h1->ProjectionY("", 3, 3);
p->Draw();

and so onโ€ฆ

Hi,

this code does not even run. Can you paste the real program?

Cheers,
D

Here is a working example which, I think, is what you are trying to achieve.

divpro.C (427 Bytes)

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