# pgfplots and errorbars

I have a file containing data points that I plot using gnuplot. The file looks as follows:

0.1 0.2 0.001
0.2 0.4 0.001
0.3 0.6 0.001


The first column represent the x axis, the second column represent the y axis and the third column represent the error over the y data.

It is possible to plot such a file, including error bars, using pgfplots and without changing it? If I have a file with four columns (x data, y data, x error, y error) the same solution apply?

This is my configuration for pgfplots:

\usepackage{pgfplots}
\pgfplotsset{%
/pgf/number format/use comma,%
/pgf/number format/1000 sep={\,},%
/pgf/number format/min exponent for 1000 sep=4}


And this is the code I usually use to create a graph:

\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[xmin=0,xmax=1000,ymin=0,ymax=1000,title={},%
xlabel={}, ylabel={},%
legend cell align=left]

file {data1.dat};
file {data2.dat};

\legend{,}
\end{axis}
\end{tikzpicture}
\caption[]{} \label{}
\end{figure}


There exist options to explicitly set the error-bars.

/pgfplots/error bars/x dir=none|plus|minus|both
/pgfplots/error bars/y dir=none|plus|minus|both
/pgfplots/error bars/z dir=none|plus|minus|both


Try to adding this options to \addplot.

UPD: Replace the file {data.dat} with table[x index=0, y index=1, y error index=2]{data.dat}, that would set x to first column, y for second and y error to third column. No file needed to be changed.

• I tried and I obtains this error: ./Figures/figure1.tex:10: Package pgfplots Error: Could not read table file 'Da ta/figure1.dat'. In case you intended to provide inline data: maybe TeX screwed up your end-of-lines? Try row sep=crcr' and terminate your lines with \\' (r efer to the pgfplotstable manual for details). What it means? – user17895 Sep 30 '12 at 14:15
• What TeX implemention you use? – m0nhawk Sep 30 '12 at 14:27
• I use MacTex-2012 – user17895 Sep 30 '12 at 14:29
• Check the newline character, for Mac this is LF. If you obtain data file from other sources (Windows or other OSes) newline character would be other - CR+LF, LF+CR, or just CR. And TeX is really frustrated with changing newline character in different parts of document. – m0nhawk Sep 30 '12 at 14:36
• How I check the newline character? I created the file with emacs on Mac OS X. The file contains the three lines I posted on the question... – user17895 Sep 30 '12 at 14:46