Whenever I try to draw a graph, I get an annoying line through y=0. This is most prominent when your data ranges from -y to +y. Strangely enough, the line disappears when I run it with earlier versions of root (e.g 5.04). Is there a way to get rid of it.
gROOT->Reset();
void sample()
{
const int N=10;
float x[N], y[N];
for (int i=0;i<N;i++) {
x[i]=i;
y[i]=i-5;
}
TCanvas* c= new TCanvas("dd","Sample graph",10,10,400,400);
TGraphErrors* gh= new TGraphErrors(N,x,y,0,0);
gh->SetTitle("The line at y=0 is no good");
gh->SetLineColor(2);
gh->GetXaxis()->SetTitle("X");
gh->GetYaxis()->SetTitle("Y");
gh->GetYaxis()->CenterTitle(true);
gh->GetXaxis()->CenterTitle(true);
gh->Draw("ac");
c->Update();
}
awesome… however, I can not upgrade to the latest version yet (group decision!!). Till then, defining a frame with appropriate xy range seems to fix the problem. e.g
{
gROOT->Reset{};
c1 = new TCanvas("c1","gerrors2",10,10,400,400);
c1->SetFillColor(42);
// draw a frame to define the range (credit: tutorials)
TH1F *hr = c1->DrawFrame(1.5,-0.75,2.5,1);
hr->SetXTitle("X title");
hr->SetYTitle("Y title");
c1->GetFrame()->SetFillColor(21);
c1->GetFrame()->SetBorderSize(12);
const Int_t N=3;
Float_t z[N]={1.6,2.0,2.4};
Float_t z1[N]={1.55,1.95,2.35};
Float_t y1[N]={0.301,0.238,0.177};
Float_t ey1[N]={0.075,0.127,0.217};
Float_t y2[N]={-0.315,-0.321,-0.327};
Float_t ey2[N]={0.038,0.06,0.1};
gy1=new TGraphErrors(N,z,y1,0,ey1);
gy1->SetMarkerStyle(24);
gy1->Draw("P"); // important.. don't use the "A" option
gy2=new TGraphErrors(N,z1,y2,0,ey2);
gy2->SetMarkerStyle(25);
gy2->Draw("P");
}