Re: [ROOT] TGraph & SetMinimum

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Dec 06 2002 - 23:09:43 MET


Hi Jeff,

Add the statement
   c->Update();
after your Draw calls, eg:

  //second plot
  c->cd(2);
  g2->Draw("AP");
  c->Update();
  g2->SetMinimum(0);


  //third plot
  c->cd(3);
  g3->Draw("AP");
  c->Update();
  g3->SetMinimum(0);

This is not necessary anymore if you use the development version in CVS.

Rene Brun

On Fri, 6 Dec 2002, Jeff Hartnell wrote:

> Hi Rene,
> I've tracked down the problem. Doing what you suggest works BUT if you
> then set the title on the axis it somehow resets the scale!!!
> 
> g->Draw("AP");
> g->SetMinimum(0);
> 
> Works just fine but
> 
> g->Draw("AP");
> g->SetMinimum(0);
> 
> g2->GetXaxis()->SetTitle("x value");
> 
> doesn't work and the scale gets reset.
> 
> See my macro below demonstrating the problem.
> 
> Cheers,
> Jeff.
> 
>   Int_t height=2000;
>   Int_t numPoints=10;
> 
>   TGraph* g=new TGraph(numPoints);
>   TGraph* g2=new TGraph(numPoints);
>   TGraph* g3=new TGraph(numPoints);
>   TGraph* g4=new TGraph(numPoints);
> 
>   for (Int_t i=0;i<numPoints;i++){
>     height+=100;
>     g->SetPoint(i,i,height);
>     g2->SetPoint(i,i,height);
>     g3->SetPoint(i,i,height);
>     g4->SetPoint(i,i,height);
>   }
> 
>   TCanvas *c=new TCanvas("c","c",0,0,1200,800);
>   c->SetFillColor(0);
>   c->Divide(2,2);
> 
>   //first plot
>   c->cd(1);
>   g->Draw("AP");
>   g->SetMinimum(0);
>   g->SetTitle("Test plot - I work");
>   g->SetMarkerStyle(3);
>   g->SetMarkerColor(2);
>   g->SetMarkerSize(0.2);
> 
>   //second plot
>   c->cd(2);
>   g2->Draw("AP");
>   g2->SetMinimum(0);
>   g2->SetTitle("Test plot - I don't work (x-axis matters)");
>   g2->SetMarkerStyle(3);
>   g2->SetMarkerColor(2);
>   g2->SetMarkerSize(0.2);
> 
>   g2->GetXaxis()->SetTitle("x value");
>   //g2->GetXaxis()->CenterTitle();
> 
>   //third plot
>   c->cd(3);
>   g3->Draw("AP");
>   g3->SetMinimum(0);
>   g3->SetTitle("Test plot - I don't work (y-axis matters)");
>   g3->SetMarkerStyle(3);
>   g3->SetMarkerColor(2);
>   g3->SetMarkerSize(0.2);
> 
>   g3->GetXaxis()->SetTitle("x value");
>   g3->GetXaxis()->CenterTitle();
>   g3->GetYaxis()->SetTitle("height");
>   g3->GetYaxis()->CenterTitle();
> 
>   //fourth plot
>   c->cd(4);
>   g4->Draw("AP");
>   g4->SetMinimum(0);
>   g4->SetTitle("Test plot - I work (SetMin last)");
>   g4->SetMarkerStyle(3);
>   g4->SetMarkerColor(2);
>   g4->SetMarkerSize(0.2);
> 
>   g4->GetXaxis()->SetTitle("x value");
>   g4->GetXaxis()->CenterTitle();
>   g4->GetYaxis()->SetTitle("height");
>   g4->GetYaxis()->CenterTitle();
>   //call again right at the end to sort it out!!!!
>   g4->SetMinimum(0);
> 
> 
> 
> ********************************************
> Jeffrey Hartnell, Oxford/RAL DPhil student.
> 
> Email: jeffrey.hartnell@physics.ox.ac.uk
> Phone numbers, addresses etc on website:
> http://www-pnp.physics.ox.ac.uk/~hartnell/
> ********************************************
> 
> ----- Original Message -----
> From: "Rene Brun" <brun@pcbrun.cern.ch>
> To: "Jeff Hartnell" <jeffrey.hartnell@physics.ox.ac.uk>
> Cc: <roottalk@cern.ch>
> Sent: Friday, December 06, 2002 2:44 PM
> Subject: Re: [ROOT] TGraph & SetMinimum
> 
> 
> > Hi Jeff,
> >
> > What you do should work
> >     g->Draw("ap");
> >     g->SetMinimum(0);
> >
> > if not, please send me a short but running script showing the problem.
> >
> > Rene Brun
> >
> > On Fri, 6 Dec 2002, Jeff Hartnell wrote:
> >
> > > Hi,
> > > It seems to be impossible to override the automatic axis scaling in
> > > TGraph when you draw it with the "a" option.
> > >
> > > I found this in the digest:
> > >
> > > From: Rene Brun (Rene.Brun@cern.ch)
> > > Date: Wed Mar 20 2002 - 10:33:17 MET
> > >
> > >   a.. Next message: Rene Brun: "Re: [ROOT] TGaxis"
> > >   b.. Previous message: Rene Brun: "Re: [ROOT] TGeant3, TGeant4 from
> > > AliSoft"
> > >   c.. In reply to: Steffen Grohmann: "[ROOT] SetRangeUser Problem on
> > > Y-axis"
> > >   d.. Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> > >
> >
> > ----------------------------------------------------------------------
> --
> > > --------
> > >
> > >
> > > Hi Steffen,
> > >
> > > When you use the option "a" in TAxis::Draw, the axis limits are
> > > automatically recomputed from the range of the actual Y values.
> > > You can force a max/min of the y axis via
> TAxis::SetMaximum/SetMinimum.
> > > An alternative solution is to use TPad::DrawFrame.
> > >
> > > Rene Brun
> > >
> > > but TAxis doesn't have SetMaximum or minimum does it?
> > >
> > > I do this:
> > >
> > > gAdcPhNear[l]->Draw("AP");
> > > gAdcPhNear[l]->SetMinimum(0);
> > >
> > > but it still gets drawn with the minimum above zero. Why doesn't
> this
> > > work? Can it be made to work?
> > >
> > > Has anyone found a solution to this problem? I could always draw a
> > > histogram first with the appropriate scale, but that's ugly!
> > > Thanks,
> > > Jeff.
> > >
> > > p.s. using latest root on redhat 7.3.1
> > >
> > >
> >
> 



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