1

Possible Duplicate:
Is there an easy way of using line thickness as error indicator in a plot?

How can I plot a function with a filled confidence band using pgfplots?

I have table data in the form (x,y,sigma), where sigma specifies the uncertainty in the y-values (standard deviation). One could plot this as a function with error bars at the data points, but I actually would like to plot this as a function with a filled confidence band. This means, that in the following example code the area between the corresponding -2*sigma and +2*sigma lines should be filled.

\documentclass{article}
\usepackage[T1]{fontenc} 
\usepackage[utf8]{inputenc} 
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.3}

\begin{document}

\pgfplotstableread{
  x    y    sigma
  1.0  1.1  0.09
  2.0  0.9  0.07
  3.0  1.3  0.08
  4.0  1.5  0.09
} \dataA

\pgfplotstableread{
  x    y    sigma
  1.0  0.3  0.07
  2.0  0.4  0.06
  3.0  0.3  0.05
  4.0  0.3  0.09
 } \dataB

\begin{tikzpicture}
\begin{axis}[
  ymin = 0.0,
  ymax = 2.0,
  xlabel = {$x$},
  ylabel = {$y$}
  ]
  \addplot [color=red!40] table[x index=0,y expr=(\thisrow{y} + 2*\thisrow{sigma})] \dataA;
  \addplot [color=red!40] table[x index=0,y expr=(\thisrow{y} - 2*\thisrow{sigma})] \dataA;
  \addplot [color=red]    table \dataA;

  \addplot [color=blue!40] table[x index=0,y expr=(\thisrow{y} + 2*\thisrow{sigma})] \dataB;
  \addplot [color=blue!40] table[x index=0,y expr=(\thisrow{y} - 2*\thisrow{sigma})] \dataB;
  \addplot [color=blue]    table \dataB;
\end{axis}
\end{tikzpicture}

\end{document}
daj
  • 11
  • 2
  • Yes, seems to be a duplicate, I haven't seen that question before, sorry. The solution shown there worked for me. – daj Sep 07 '12 at 12:50
  • No problem, that other question isn't particularly easy to find. It's good to have this question as a second "entry point". Welcome to the site, by the way. – Jake Sep 07 '12 at 12:55

0 Answers0