[Tex/LaTex] Error bars as shaded area

error barspgfplotstikz-pgf

I'm wondering if there is a possibility for Latex to display the error bars of a curve or series of data points as a shaded area rather than individual bars on the points; something like this question. I browsed through the pgfplots manual and found nothing of the sorts.

My idea so far is to plot the y-error and y+error as solids and fill the space between both of them, as is done in this other question.

An example of what I mean: the top image has regular error bars, and the bottom image has error bars as a shaded area (done with Python according to this question.

Plot with regular error bars
Plot with error bars as shaded area

Best Answer

A quick example with pgfplots and the fillbetween library:

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{data.dat}
x y err
0 1 0.1
1 1.5 0.3
2 2 0.2
\end{filecontents*}

\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot table[x=x,y=y] {data.dat};

\addplot [name path=upper,draw=none] table[x=x,y expr=\thisrow{y}+\thisrow{err}] {data.dat};
\addplot [name path=lower,draw=none] table[x=x,y expr=\thisrow{y}-\thisrow{err}] {data.dat};
\addplot [fill=blue!10] fill between[of=upper and lower];
\end{axis}
\end{tikzpicture}

\end{document}