Problem using TCanvas::Divide() and TLine together

Hi,

I have, say, a TCanvas c0 with a 2x2 grid of plots created using c0->Divide(2,2). I would like to draw a vertical line on only one of the plots using TLine; however, the line doesn’t show up at all. Below is an MWE:

[code]{
TCanvas *c0 = new TCanvas(“c0”,“canvas0”);

TH1F *h0 = new TH1F("h0","h0",100,-1,1);
TH1F *h1 = new TH1F("h1","h1",100,-1,1);
TH1F *h2 = new TH1F("h2","h2",100,-1,1);
TH1F *h3 = new TH1F("h3","h3",100,-1,1);

h0->FillRandom("gaus");
h1->FillRandom("gaus");
h2->FillRandom("gaus");
h3->FillRandom("gaus");

c0->Divide(2,2);

c0->cd(1);
h0->Draw();

c0->cd(2);
double x1 = 0.4;
TLine *line1 = new TLine(x1,0,x1,c0->GetFrame()->GetY2());
line1->SetLineWidth(2);
line1->SetLineColor(kRed);
line1.Draw();
h2->Draw();

c0->cd(3);
h2->Draw();

c0->cd(4);
h3->Draw();

}[/code]

Thanks in advance for any feedback!

c0->cd(2); h1->Draw(); double x1 = 0.4; TLine *line1 = new TLine(x1,0,x1,c0->GetFrame()->GetY2()); line1->SetNDC(kTRUE); line1->SetLineWidth(2); line1->SetLineColor(kRed); line1.Draw();

That doesn’t quite solve it, unfortunately. It puts a red line at NDC x-coord 0.4, but I would like it to correspond to the x-value 0.4 on the plot. Also, the line extends beyond the frame of the plot both at the top and bottom.

c0->cd(2); h1->Draw(); gPad->Modified(); gPad->Update(); // make sure it's really drawn double x1 = 0.4; TLine *line1 = new TLine(x1, gPad->GetFrame()->GetY1(), x1, gPad->GetFrame()->GetY2()); line1->SetLineWidth(2); line1->SetLineColor(kRed); line1.Draw();

Perfect, thanks! Using gPad->GetFrame() instead of c0->GetFrame() seemed to do the trick.