Hi Pietro,
> 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:
I cannot reproduce what you say, I get the error in both cases
(both as a sequence of prompt commands and macro, ROOT 3.03/06);
the reason is that
root [3] TGraph *gr = new TGraph (5,x,y);
root [4] cout << gr->GetXaxis() << endl;
(nil)
which is related to TGraph painting.
the following seems to me well working
void TGraph_example()
{
gROOT->Reset();
c1 = new TCanvas("c1","Pietro Graph",200,10,700,500);
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->Draw("AC*");
c1->Update();
gr->GetXaxis()->SetRangeUser(0.2,0.4);
c1->Modified();
}
Hoping it is usefull, regards
Fabrizio
+=======================================================+
|| Fabrizio Pierella ||
|| E-mail: Fabrizio.Pierella@cern.ch ||
|| pierella@bo.infn.it ||
|| Tel. CERN (Bld.29-R-019) +41 (22) 7677767 ||
|| in Bologna (off.203) +39 051 2091103 ||
+=======================================================+
On Tue, 9 Jul 2002, 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