Re: Q: TGraphErrors/TGraph options

Rene Brun (Rene.Brun@cern.ch)
Thu, 29 May 1997 08:13:22 +0200


Pasha Murat wrote:
>
> Hi,
>
> if in the following macro (which has been stolen from the ROOT class manual)
> I change gr->Draw("AP") into gr->Draw("A") or gr->Draw("P") nothing
> happens on the screen except a segment is drawn on the right side of the canvas.
> Is it a supposed behaviour?
> --------------------------------------------------------------------------------
> {
> gROOT->Reset();
> gStyle->SetFillColor(0);
> graph = new TCanvas("graph","A Simple Graph with error bars",200,10,700,500);
>
> Int_t n = 10;
> Float_t x[n] = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95};
> Float_t y[n] = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1};
> Float_t ex[n] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05};
> Float_t ey[n] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8};
>
> gr = new TGraphErrors(n,x,y,ex,ey);
> gr->SetTitle("TGraphErrors Example");
> gr->SetMarkerColor(1);
> gr->SetMarkerStyle(20);
> gr->Draw("AP");
> graph->Update();
> }
>

The option "A" in TGraph::Draw computes the graph range , clear
the pad and draw the Axis. The statement gr->Draw("P") draws only
the graph in the current pad.
The reason why you see only part of the picture is that the default
canvas range is [0,1] in x and y.
You could have set the canvas/pad range, example:
graph->Range(-0.3,-1,1.1,12);
gr->Draw("P");
In this case you will see the complete graph without the axes.

--------------------------------------------------------------------------------
> Another relevant question:
>
> I need to superimpose 2 sets of experimental points. To do this in PAW one
> uses the following command sequence:
>
> > hplot/null ..... * define dimensions of the plot
> > hplot/err .... * plot 1st set of points
> > hplot/err .... * plot 2nd set of points
>
> What is the equivalent command sequence of ROOT commands?
You can do for example:
TH2F *frame = new TH2F("frame","title",2,xmin,xmax,2,ymin,ymax);
frame->Draw();
gr1->Draw("lp");
gr2->Draw("lp");

> It would be very helpful to include an example of how to do this into ROOT
> manual/tutorials - this is one of the very basic things people are doing.
>

I will add a new tutorial.

Rene Brun