Until this is implemented properly in PGFplots, you can abuse the scatter/@pre marker code
key for drawing colored error bars. I've defined a key error bars with mapped color=<error source>
, which will set the necessary keys, so that
\addplot [
scatter,
scatter src=\thisrow{class},
error bars with mapped color=err,
error bars/.cd,
y dir=both,
y explicit
]
table[x=x,y=y,y error=err] {
x y err class
0 0 1 0
1 1 1 0
2 0 1 1
3 2 2 1
};
\end{axis}
will give you

A couple of problems with this solution:
The colored error bars at the moment assume that the error is absolute, and in positive and negative y-direction. Different error bar types would have to be adjusted manually in the error bars with mapped color
style (it wouldn't be enough to change the relevant error bars
styles).
When the plot marks and the colored error bars are drawn, the coordinate system is scaled in a bit of an unusual way (in increments of powers of ten) depending on the data range. I haven't figured out how to access the scaling factor automatically, so you might have to set this factor manually depending on your data range.
Here's the code:
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\pgfplotsset{
error bars with mapped color/.style={
disabledatascaling,
visualization depends on=\thisrow{#1} \as \error,
visualization depends on=\thisrow{y} \as \y,
scatter/@pre marker code/.append style={
/pgfplots/error bars/.cd,
error mark options={draw=mapped color},
error mark=|,
draw error bar={(0,0)}{(0,\error*100)}, % *100 to correct for the scaling
draw error bar={(0,0)}{(0,-\error*100)} % might have to be adjusted (0.1,1,10,100,...)
},
scatter/@post marker code/.append code={}
}
}
\begin{tikzpicture}
\begin{axis}[colorbar right, colorbar sampled, colorbar style={samples=3},
point meta min=-0.5, point meta max=1.5,
scatter/use mapped color={draw=mapped color, fill=mapped color}]
\addplot [
scatter,
scatter src=\thisrow{class},
error bars with mapped color=err,
error bars/.cd,
y dir=both,
y explicit
]
table[x=x,y=y,y error=err] {
x y err class
0 0 1 0
1 1 1 0
2 0 1 1
3 2 2 1
};
\end{axis}
\end{tikzpicture}
\end{document}
pgfplots sourceforge site