Hi,
To retrives the axis from a TGraph, you need to draw the graph first,
only then does it actually have an axis object. Once drawn, you set the
range, draw again and update the canvas.
TCanvas c1 = new TCanvas("c1","graph",10,20,200,400);
TGraph *gr = new TGraph (5,x,y);
gr->Draw("AC*");
gr->GetXaxis()->SetRangeUser(0.2,0.4);
gr->Draw("AC*");
c1->Update();
Regards
Ernesto
On Tue, 9 Jul 2002, Marcos wrote:
> Hello Pietro
> I think that if you use gr->GetXaxis->SetLimits(0.2,0.4) will work, it worked
> for me. :)
>
> Pietro Govoni wrote:
>
> > Dear rooters,
> > I'm trying to draw Tgraph in a certain range, narrower than the
> > definition's one.
> > The code I'm using is a simple example:
> >
> > void TGraph_example()
> > {
> > Double_t x[5];
> > Double_t y[5];
> > for (Int_t i=0; i<5; i++) {x[i]=0.1*i;y[i]=10*sin(x[i]+0.2);}
> > TGraph *gr = new TGraph (5,x,y);
> > gr->GetXaxis()->SetRangeUser(0.2,0.4);
> > gr->Draw("AC*");
> > }
> >
> > When I use it as a sequence of prompt commands everything works properly,
> > but if I try to let ROOT execute them as a macro I get this error:
> >
> > Processing TGraph_example.C...
> > Error: illegal pointer to class object GetXaxis() 0x0 126
> > FILE:TGraph_example.C LINE:9
> > *** Interpreter error recovered ***
> >
> > This is my version of root:
> >
> > * Version 3.03/05 1 May 2002 *
> >
> > Is there anything that I forgot?
> > Thank you for your attention, regards
> >
> > pietro
>
>
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:59 MET