Setting TPad range in user coordinates

When drawing a TGraph on a TPad, the range of the TPad axes is set automatically. But sometimes you want to set it by hand, to align several plots, etc. It seems that TPad::Range(…) is the function to call to do this, but it doesn’t do anything. Here is an example code:

TCanvas * can = new TCanvas(“can”, “”, 500, 500);
TPad * pad = new TPad (“pad”, “”, 0, 0.5, 1, 1);
pad->Range(-2, -4, 10, 10);
pad->Draw();
gPad = pad;

float x[5] = {1,2,3,4,5};
float y[5] = {2,6,-1,3,-2};

TGraph * g = new TGraph(5, x, y);
g.Draw(“al”);

The line pad->Range(-2, -4, 10, 10); is supposed to set the range of the pad axes as specified, but it doesn’t do anything. Trying to make this call after Draw() and calling pad->Update() doesn’t help either. Am I misunderstanding something and there is in fact a different way to do this?

Thanks,
Abi

You should do:

g.Draw("l");

not:

g.Draw("al");

A is the option which forces the axis definition.
(see doc: root.cern.ch/root/html/TGraphPainter.html#GP01)

But calling g->Draw(“l”) results in a plot that has no axes whatsoever. I do want axes, I just want them i the range that I set and not in the automatic range set by g->Draw(“al”).

Thanks,
Abi

[code]{
TCanvas *can = new TCanvas(“can”, “”, 500, 500);
TPad *pad = new TPad (“pad”, “”, 0, 0.5, 1, 1);
pad->Draw(); pad->Update();
pad->cd();
gPad->DrawFrame(-2, -4, 10, 10, “WTF?;something on X;something on Y”);

float x[5] = {1,2,3,4,5};
float y[5] = {2,6,-1,3,-2};

TGraph * g = new TGraph(5, x, y);
g->Draw(“l”);
}[/code]

But calling g->Draw("l") results in a plot that has no axes whatsoever. I do want axes, I just want them i the range that I set and not in the automatic range set by g->Draw("al").

You did not specified you wanted the axis.
If you want them W.E.C. solution is the right answer.

This works. Thanks!

Abi