Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[ROOT] Drawing part of a TGraphErrors

37 views
Skip to first unread message

Ann-Cecilie Larsen

unread,
Feb 19, 2007, 11:24:22 AM2/19/07
to RootTalk
Dear Rooters,

I am trying to plot only a part of a graph with error bars using the following statements in my macro:

// make graph
TGraphErrors *gr_fg3 = new TGraphErrors(n,energy,fg3,xerr,fgerr3); // for fg
// creating histogram (just for the axis)
TH2F *h1 = new TH2F("h1"," ",10,0.0,8.0,10,0.0,1.0);
h1->Draw(); // draw axis
gr_fg3->SetMarkerStyle(21);
gr_fg3->SetMarkerSize(0.6);
gr_fg3.DrawGraph(8,&gr_fg3->GetX()[5],&gr_fg3->GetY()[5],"P"); // draw fg data

But the error bars disappear in the pad... Is there another function than DrawGraph that should be used with the TGraphErrors?

Cheers, Cecilie

====================================

Ann-Cecilie Larsen

Oslo Cyclotron Laboratory (http://ocl.uio.no/)

Department of Physics, University of Oslo

P.O.Box 1048 Blindern

N-0316 Oslo, Norway

Phone: +47 22 85 64 63 Fax: +47 22 85 64 22

E-mail: a.c.l...@fys.uio.no

====================================


Olivier Couet

unread,
Feb 19, 2007, 11:42:49 AM2/19/07
to a.c.l...@fys.uio.no, RootTalk
May be something like that would be simpler:

{
Int_t n=20;
Double_t x[n],y[n];
for (Int_t i=0; i < n; i++) {
x[i]=i*0.1;
y[i]=10*sin(x[i]+0.2);
}
TGraph *gr1 = new TGraph (n,x,y);
TAxis *axis = gr1->GetXaxis();

axis->SetLimits(0.,5.); // along X
gr1->GetHistogram()->SetMaximum(20.); // along
gr1->GetHistogram()->SetMinimum(-20.); // Y

gr1->Draw("AC*");
}


________________________________

Ann-Cecilie Larsen

unread,
Feb 19, 2007, 1:31:06 PM2/19/07
to Olivier Couet, RootTalk
Dear Olivier,

19. feb. 2007 kl. 17.42 Olivier Couet wrote:


May be something like that would be simpler:


{
Int_t n=20;
Double_t x[n],y[n];
for (Int_t i=0; i < n; i++) {
x[i]=i*0.1;
y[i]=10*sin(x[i]+0.2);
}
TGraph *gr1 = new TGraph (n,x,y);
TAxis *axis = gr1->GetXaxis();

axis->SetLimits(0.,5.); // along X
gr1->GetHistogram()->SetMaximum(20.); // along
gr1->GetHistogram()->SetMinimum(-20.); // Y

gr1->Draw("AC*");
}

Thanks so much for your suggestion, but unfortunately it doesn't help me. The data file I am reading to get the TGraphErrors contains zeroes, and if I plot the whole graph also the zero points appear with markers. This I would like to avoid, and therefore I tried to use the DrawGraph function, which is perfect for a TGraph.

Cheers, Cecilie

Olivier Couet

unread,
Feb 20, 2007, 4:16:59 AM2/20/07
to a.c.l...@fys.uio.no, RootTalk
Dear Cecilie,

Can you send me a small running example ?
The few lines you sent before are not complete.

Cheers, Olivier

________________________________

an132....@gmail.com

unread,
Jul 19, 2014, 3:20:47 AM7/19/14
to
Dear Ann,

Did you find the solution to this problem. 7 years after you, but I'm also stuck on a similar problem.

Please share the solution that you found, so that I too can use it
0 new messages