Problem with TLine and resizing of x-axis

Dear Root Experts,

The problem is being illustrated with the following simplified code:

{
 TH1D *hist = new TH1D("histName","histTitle",10,0.,10.);
 hist->GetYaxis()->SetRangeUser(0.,2.);
 TLine *line = new TLine(0.,1.,10.,1.);
 line->SetLineColor(kRed);
 hist->Draw();
 line->Draw("same");
}

Upon execution I am getting what is attached in the file beforeResizing.png. Now with the mouse I want to resize the x-axis, but then TLine object goes out of boundaries - see afterResizing.png.

Is there any way to force TLine to automatically obey new range on x-axis after resizing with the mouse?

Thanks and cheers,
Ante

P.S. ROOT 5.26/00b (tags/v5-26-00b@32327, Mar 28 2010, 16:02:56 on linuxx8664gcc)




Basic primitives such as Tline, TText do not know about the frame created when drawing histograms and graphs.
In your case simply replace Tline by TGraph as show below

Rene

{ TH1D *hist = new TH1D("histName","histTitle",10,0.,10.); hist->GetYaxis()->SetRangeUser(0.,2.); //TLine *line = new TLine(0.,1.,10.,1.); TGraph *line = new TGraph(2); line->SetPoint(0,0,1); line->SetPoint(1,10,1); line->SetLineColor(kRed); hist->Draw(); line->Draw("l"); }

1 Like

Dear Rene,

Thanks for a quick reply - TGraph will indeed do the job!

Cheers,
Ante