How to change the range of a TGraphErrors for Drawing


I would like to plot a TGraphError object, the first time with all the data and the second time on a zoomed region, I was thinking to use just like TH1 the XAxis options but it’s not working :

  //   3.2 Draw the likelihood
  //   ***********************
  m_canvas  -> cd(2) ; 
  gPad      -> SetGrid() ;
  graph_llh -> Draw("AP") ;

  //   3.3 Draw the likelihood (ZOOM)
  //   ******************************
  m_canvas  -> cd(3) ;
  gPad      -> SetGrid() ;
  graph_llh -> GetXAxis() -> SetRangeUser(zoom_low, zoom_high ) ;
  graph_llh -> Draw("AP") ;

What would be the normal way to do i t?
Which part of the manual talks about that ?


My mistake it’s working fine I just made a typo : GetXAxis() -----> GetXaxis()


   c1 = new TCanvas("c1","A Simple GraphErrors Example",200,10,700,500);
   const Int_t n = 20;
   Double_t x[n], y[n], ex[n], ey[n];
   for (Int_t i=0;i<n;i++) {
     x[i]  = i*0.1;
     y[i]  = 10*sin(x[i]+0.2);
     ex[i] = 0.08;
     ey[i] = 0.1*i;
   TGraphErrors *gr = new TGraphErrors(n,x,y,ex,ey);

   TGraphErrors *gr2 = gr->DrawClone("AP");


Thanks for the hlep, I followed your instruction but had the following resutls :

ROOT-ine.cxx: In function ‘TCanvas* Make_lla(TH1D*, std::vector<TH1D*, std::allocator<TH1D*> >, double*, std::string*)’:
ROOT-ine.cxx:1801: error: invalid conversion from ‘TObject*’ to ‘TGraphErrors*’

Any idea why is it not compiling ?

Ok I’ve found something that suits me, I use the following :

What Isent you was an example macro running in interactive mode using CINT. Of course if you include that piece of code in a compiled program (or if you use ru it using AClic) you should add all the needed include files.

Indeed I use this bit of code in a compiled program but I took care to put all the *.h i need, here is the list :

// C++ headers
# include <iostream>
# include <cmath>
# include <fstream>
# include <sstream>
# include <iomanip>

using namespace std ;

// ROOT headers
# include "TROOT.h"
# include "TApplication.h"
# include "TFile.h"
# include "TCanvas.h"
# include "TH1.h"
# include "TF1.h"
# include "TGraph.h"
# include "TGraphErrors.h"
# include "TLegend.h"
# include "TPaveText.h"
# include "TStyle.h"
# include "TLine.h"

Tell me which one was missing to use your method. Anyway the stuff I wrote works nicely.

Thanks for your help !

in fact you should do:

TGraphErrors *gr2 = (TGraphErrors *) gr->DrawClone(“AP”);

CINT is more flexible than compilers.

I prefer compiler though they are safer…

Sure, no problem. But then you should declare the new graph as mentionned in my last post. As I said, as CINT is more fexible, it allows the kind of construct I first sent, but compilers don’t. Therefore you should do the cast as shown in my last post.

Ok then, thanks for tip.
By the way any idea how to change the style of the font for the axis for a TGraphErrors object, apparently it does not work just like for the TH1.



It works perfectly !! Thanks a lot for your efficient help !