Re: [ROOT] Setting axes for graphs

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Mar 08 2002 - 08:37:39 MET


Hi Maurizio,

The X,Y axis objects do not exist before calling TGraph::Draw.
See your modified code to set the range for TGraphs.

Rene Brun

{
const Int_t n1=12;
Double_t x1[n1];
const Double_t y1[n1] = {
  18.606, 26.434, 32.393, 37.443, 41.799, 45.858,
  49.540, 52.971, 56.183, 59.204, 62.078, 64.832
};

for (Int_t i = 0;  i < n1;  ++i) x1[i]=sqrt(i+1);

TCanvas *c1 = new TCanvas("c1", "c1");
c1->SetFillColor(0);
c1->DrawFrame(0,10,4,70);

TGraph *g1 = new TGraph(n1, x1, y1);
g1->SetMarkerStyle(2);
g1->SetMarkerSize(0.9);
g1->Draw("P");
}


Maurizio Loreti wrote:
> 
> Hi there -
> I am trying to make a slide with some data.  The file I am using with root
> (version 3.02.07, linux distribution 6.1/egcs) is:
> 
> {
> const Int_t n1=12;
> Double_t x1[n1];
> const Double_t y1[n1] = {
>   18.606, 26.434, 32.393, 37.443, 41.799, 45.858,
>   49.540, 52.971, 56.183, 59.204, 62.078, 64.832
> };
> 
> for (Int_t i = 0;  i < n1;  ++i) x1[i]=sqrt(i+1);
> 
> TCanvas *c1 = new TCanvas("c1", "c1");
> c1->SetFillColor(0);
> 
> TGraph *g1 = new TGraph(n1, x1, y1);
> g1->SetMarkerStyle(2);
> g1->SetMarkerSize(0.9);
> // g1->GetXaxis()->SetLimits(0.0, 4.0);
> // g1->GetYaxis()->SetLimits(10.0, 70.0);
> g1->Draw("AP");
> }
> 
> So far, so good.  ".x foo.C" does what it is supposed to do.  But - if I
> try to define the X- and Y-axis limits to some integer/meaningful number
> in the two commented lines, I get "*** Break *** segmentation violation".
> 
> What am I doing wrong?  x->GetXaxis()->SetLimits() works correctly if x
> points to an histogram.  What is the way to change the axis limits for
> graphs?
> 
>                 TIA,    M.
> 
> --
> Maurizio Loreti                         http://www.pd.infn.it/~loreti/mlo.html
> Univ. of Padova, Dept. of Physics - Padova, Italy            loreti@pd.infn.it



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:45 MET