Cannot draw error bar with SetMarkerStyle when the errors are small in TGraphErrors


Please read tips for efficient and successful posting and posting code

_ROOT Version:6.26/10
_Platform:Ubuntu 22.04
_Compiler:g++ 11.3


When I use this code below, it works properly.

{
   gStyle->SetEndErrorSize(5.0); 
   // or 
   //gStyle->SetErrorX(5.0);

   TCanvas *c4 = new TCanvas("c4","c4",200,10,600,400);
   double x[] = {0, 1, 2, 3, 4};
   double y[] = {0, 2, 4, 1, 3};
   double ex[] = {0.1, 0.2, 0.3, 0.4, 0.5};
   double ey[] = {1, 0.5, 1, 0.5, 1};
   TGraphErrors* ge = new TGraphErrors(5, x, y, ex, ey);
   ge->Draw("AP");
   return c4;
}

I reduce the first point’s ex and ey, the code still draw error bars. And because the small errors, the error bars overlap, which is meaningful that can tell us the errors are very small.

{
   gStyle->SetEndErrorSize(5.0); 
   // or 
   //gStyle->SetErrorX(5.0);

   TCanvas *c4 = new TCanvas("c4","c4",200,10,600,400);
   double x[] = {0, 1, 2, 3, 4};
   double y[] = {0, 2, 4, 1, 3};
   double ex[] = {0.001, 0.2, 0.3, 0.4, 0.5};
   double ey[] = {0.001, 0.5, 1, 0.5, 1};
   TGraphErrors* ge = new TGraphErrors(5, x, y, ex, ey);
   ge->Draw("AP");
   return c4;
}

But if I set the style of markers, the error bars of first point disappear, only the mark on the pad. No matter I use SetEndErrorSize or SetErrorX.

{
   gStyle->SetEndErrorSize(5.0); 
   // or 
   //gStyle->SetErrorX(5.0);

   TCanvas *c4 = new TCanvas("c4","c4",200,10,600,400);
   double x[] = {0, 1, 2, 3, 4};
   double y[] = {0, 2, 4, 1, 3};
   double ex[] = {0.001, 0.2, 0.3, 0.4, 0.5};
   double ey[] = {0.001, 0.5, 1, 0.5, 1};
   TGraphErrors* ge = new TGraphErrors(5, x, y, ex, ey);
   ge->SetMarkerStyle(23);
   ge->Draw("AP");
   return c4;
}

The errors of the first point are very small and are “covered” by the “big” marker. Try to set “0.1” instead of “0.001”.

BTW. Without the “big” marker, for the first point, you do not see the “error bars” but the “lines at the end of error bars” (which unfortunately form a misleading cross).

Thanks for your reply. But I have real data that some of the errors are very small. In this case, as you have said, the errors of the some points are very small and are “covered” by the “big” markers. I can’t simply set big errors wich is not the true data to fix this problem. So I think this’s a little bug.

@couet For me, it’s the opposite … the “bug” is that ROOT draws long “lines at the end of error bars”, which then form a misleading cross (which “mimics” error bars without end lines).

The error bar lengths have to correspond to the error size, so if they are too small for the scale of the plot, you won’t see them; I don’t think that’s a bug (the bug could be what Wile said). If you zoom in enough (a lot in your case) on the first point of the graph, you will actually see the bars when they get larger than the markers (as the markers don’t change size when zooming), but then you won’t see the other points.

The default is:

{
   double x[] = {0, 1, 2, 3, 4};
   double y[] = {0, 2, 4, 1, 3};
   double ex[] = {0.001, 0.2, 0.3, 0.4, 0.5};
   double ey[] = {0.001, 0.5, 1, 0.5, 1};
   TGraphErrors* ge = new TGraphErrors(5, x, y, ex, ey);
   ge->Draw("AP");
}

it gives:


for the point at (0,0) any marker different than a dot (default) will cover the errors ( and that’s why dot is the default). There is no other way than using the marker “.”…

Also notice: ROOT: tutorials/graphics/markerwarning.C File Reference

@couet Note that the “cross” at (0,0) is misleading. The drawn lines do NOT represent the actual errors (they are the “end lines” of the invisible small errors). I would say, in such cases, these lines should be removed.

    gStyle->SetEndErrorSize(0);

It’s really strange. After using SetEndErrorSize , the end lines at the error bars are bigger than the markers, but they’re still covered by the markers. Is there any plan to fix this problem?

@couet Yes, I know. But this unconditionally removes the “end lines” from all points.

Yes, which seems more coherent…

@couet Well, if you think it’s “more coherent” … then I agree with @iyuicu that the “end lines” should also be drawn when the marker covers the errors.

which value to you set for the end error size ? can you post the code you think is faulty ?

Try, e.g., the last macro from the first post here (and instead of “5.0”, try, e.g., “55.0”).

void iy(){
   gStyle->SetEndErrorSize(55);
   double x[] = {0, 1, 2, 3, 4};
   double y[] = {0, 2, 4, 1, 3};
   double ex[] = {0.001, 0.2, 0.3, 0.4, 0.5};
   double ey[] = {0.001, 0.5, 1, 0.5, 1};
   TGraphErrors* ge = new TGraphErrors(5, x, y, ex, ey);
   ge->SetMarkerStyle(23);
   ge->Draw("AP");
}

gives … a non sense seems to me… but root does what is requested.

So, I get NO lines for the point at (0.0).

Yes … the big “errors” you see at 0,0 are the end lines … I am lost …

That’s really confusing. In my ROOT, I have NO line at (0, 0).

I say I DO NOT get these lines drawn for the first point at (0.0), exactly like @iyuicu shows.

I am running on Mac with ROOT master amd I get the lines . That quite surprising indeed because that should not depend on the machine (ie line are drawn or not). I will try with 6.26

1 Like