Errorbars in ROOT 6


I have a program (using ROOT libraries, not a macro) which uses the TGraphErrors class. I initialize an object with data from a file (4 columns, x,y,ex,ey) and draw it. When I do, the errorbars don’t appear, although I know the error values are there because I can print them directly from the object.

This problem doesn’t happen with THist classes (don’t know if it is relevant).

Also, while I have this problem using ROOT 6, a friend of mine compiled it and ran it with ROOT 5 and obtains the graph with errorbars.

Does anyone know if this is common or what could be happening?


the errorbars can be correctly visualised with root 6.06, most probably with other versions of the 6 series.
input file:

# x    y    ex    ey
  1.   0.4  0.1   0.05
  1.3  0.3  0.05  0.1
  1.7  0.5  0.15  0.1
  1.9  0.7  0.05  0.1
  2.3  1.3  0.07  0.1
  2.9  1.5  0.2   0.1


#include "TGraphErrors.h"
#include "TCanvas.h"
int main() {
TGraphErrors g("ExampleData.txt");
TCanvas c;
return 0;

Plot attached.

Can you verify that you can visualise the data above correctly?

Thank you for your answers and sorry for the delay…

@Pepe Le Pew:
Tried your suggestion, did not work. The output comes the same, without errorbars, only the graph and the fit function.

I ran the code you put here, it worked perfectly. In my program I was using:

TGraphErrors g("ExampleData.txt","%lg %lg %lg %lg");
which is equivalent. I altered it just to be certain and it changed nothing.

After I initialize my TGraphErrors I put it in a TMultiGraph (I forgot to say it before). Could this be related?


may you try (a macro but not an executable, it does not make any difference at this level):

void graph(){
TGraphErrors g("ExampleData.txt");
auto c = new TCanvas();
TMultiGraph  mg;


Danilo raised an interesting issue (note “DrawClone” instead of “Draw” in the previous post).
You seem to create your graph “on stack” (i.e. without “new”). It is possible that after you add it to your multigraph and before you draw (and print) your multigraph, the original graph gets “out of scope”, so it automatically gets destroyed (but the multigraph still keeps the “invalid” address of it).

The macro you posted worked perfectly too.

I allocate both the TMultiGraph and the TGraphErrors with new, so I think I’m safe on that point. Also, I make modifications to the MultiGraph after drawing it (SetMinimum, SetMaximum) and using DrawClone gives a segmentation violation there.

Well, if DrawClone results in segmentation violation then I would say that there is at least one graph which no longer exists (a TMultiGraph owns graphs which were added, so you must not delete them yourself).

Note also that you could try something like:
TMultiGraph *MyClone = (TMultiGraph *)OriginalMultiGraph->DrawClone(“AP”);
gPad->Modified(); gPad->Update(); // make sure it’s really (re)drawn
gPad->Modified(); gPad->Update(); // make sure it’s really (re)drawn

Sorry, I wasn’t very clear. What I meant was that if I use DrawClone the following methods (i.e. SetMinimum) give segmentation violation. Not the DrawClone itself. At least that’s the line at which ROOT points.


without a minimal reproducer, standalone, which hints to a issue in root, I am afraid we cannot help much more.


I was making a simpler version of my error when and, while simplifying, I no longer had the problem. By trial and error, I found out that this:

was the problem.

SetLineWidth accepts an integer as argument and, receiving a float, it simply truncated and used 0 as the width. My colleague with ROOT 5 had the same line of code but, apparently, it was being rounded up. Why the different behaviour, I still don’t know (I took a look at ROOT reference for both versions and the source code defining line width seemed the same…).

Anyway, problem solved. Thank you very much for your help (and time spent)!