I want a grouped scatter plot with xy error bars and a legend. So each point is a different group, with its own color, mark, and legend entry. The error bars should have the same color as the mark they belong to.
Here is an edited example from this answer:
\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}[
scatter/use mapped color={draw=mapped color, fill=mapped color},
scatter/classes={ a={mark=*,draw=red,fill=red!50},b={mark=square*,draw=green,fill=green!50},c={mark=triangle*,draw=magenta,fill=magenta!50} }
]
\addplot [
scatter,
only marks,
scatter src=\thisrow{class},
scatter src=explicit symbolic,
error bars with mapped color=err,
error bars/.cd,
y dir=both,
y explicit
]
table[x=x,y=y,y error=err,meta=meta] {
x y err class meta
0 0 1 0 a
1 1 .1 0 a
2 0 1 1 b
3 -.5 .2 2 c
};
\legend{Worlds,People,Barnacles}
\end{axis}
\end{tikzpicture}
\end{document}
But you'll notice that the "brackets" of the error bars are not colored correctly. I haven't managed creating x-error bars at the same time.
Maybe, by now, there is an altogether better solution than @Jake suggested?

