Re: [ROOT] problem with graph and axis titles

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Nov 26 2003 - 18:04:30 MET


Hi Mariusz,

I cannot reproduce your problem.
Please always report the version number that you are using!

The following script works:

{
   c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500);
   c1->DrawFrame(0,2,2.2,11);
   const Int_t n = 20;
   Double_t x[n], y[n];
   for (Int_t i=0;i<n;i++) {
     x[i] = i*0.1+0.05;
     y[i] = 10*sin(x[i]+0.2);
   }
   gr = new TGraph(n,x,y);
   gr->SetMarkerStyle(21);
   gr->Draw("P");

   c1->Update();
   gr->GetHistogram()->GetXaxis()->SetTitle("layer No");
   c1->Modified();
}

You may also consider the following simpler solution. See the way
to specify the global, x and y title.

{
   c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500);
   const Int_t n = 20;
   Double_t x[n], y[n];
   for (Int_t i=0;i<n;i++) {
     x[i] = i*0.1+0.05;
     y[i] = 10*sin(x[i]+0.2);
   }
   gr = new TGraph(n,x,y);
   gr->SetTitle("graph title;x title;y title");
   gr->SetMarkerStyle(21);
   gr->Draw("AP");
}

Rene Brun

Mariusz Sapinski wrote:
> 
>  I got the following code (fragments):
> 
> -------------------------
> 1  TGraph * gr1 = new TGraph(nlayer, layer, E05_10);
> 2
> 3  TCanvas * c1 = new TCanvas("c1","c1",10,10,400,400);
> 4  c1->DrawFrame(3.5,-32.8.,18,-32.2);
> 5
> 6  gr1->Draw("P");   // or (AP)
> 7  c1->Update();
> 8  gr1->GetHistogram()->GetXaxis()->SetTitle("layer No");
> 9
> 10 c1->Modified();
> -----------------
> 
>  Now the problem is that if i do not comment 8th line, the graph
> disappears just after being plotted. And anyway this line is not working
> with P option only (in line 6). But if i put AP option then two scales are
> plotted on Y axis (the one of graph and the one superimposed in line 4).
> 
>  How to do to have axis title, single scale on Y axis and a visible points
> of the graph?
> 
> --
> Mariusz



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:17 MET