# pgfplots: lines and markers in different colors

With pgfplots, I am creating a simple coordinate plot with error bars like this:

\documentclass[crop,10pt]{standalone}
\usepackage[english]{babel}
\usepackage{pgfplots}

\begin{document}%
\setlength{\linewidth}{246pt}%

\begin{tikzpicture}
\begin{axis}[
width=\linewidth,
ytick pos = left,
xtick pos = left,
clip=false,
axis on top,
tick align = outside,
yticklabel style={%
/pgf/number format/fixed,
/pgf/number format/precision=1,
/pgf/number format/fixed zerofill
},
ytick scale label code/.code={},
xlabel={X},
ylabel={Y},
]
plot[
error bars/.cd,
y dir=both,
y fixed=0.0001
]
coordinates{(1,0.0005) (1.1,0.0013) (5,0.0015)};
\end{axis}
\end{tikzpicture}
\end{document}


In the original plot I have a lot more points. I would now like the line and the markers (including the error bars) to have different colors to better distinguish the line from the error bars. Is that somehow possible? The only way I found so far is to plot the data just as a line in one color and then plot it again just as markers in another color. This works, but I guess there must be some better solution to this.
Thanks for the support,
John

-

You have to set the error bars/error bar style and mark options keys in order to change the colors of both error bars and markers. I put these options in the \addplot command, because you could need to set different colors for different lines, but you could put them among the axis options too.

\documentclass[crop,10pt]{standalone}
\usepackage[english]{babel}
\usepackage{pgfplots}

\begin{document}%
\setlength{\linewidth}{246pt}%

\begin{tikzpicture}
\begin{axis}[
width=\linewidth,
ytick pos = left,
xtick pos = left,
clip=false,
axis on top,
tick align = outside,
yticklabel style={%
/pgf/number format/fixed,
/pgf/number format/precision=1,
/pgf/number format/fixed zerofill
},
ytick scale label code/.code={},
xlabel={X},
ylabel={Y},
]
mark=*,
mark options={green},
error bars/error bar style={red},
]
plot[
error bars/.cd,
y dir=both,
y fixed=0.0001
]
coordinates{(1,0.0005) (1.1,0.0013) (5,0.0015)};
\end{axis}
\end{tikzpicture}
\end{document}


-
+1: Perhaps the axis labels would be better in math mode: xlabel={$x$}, and same for y-axis. I see that the OP posted it that way, but might as well suggest that as an enhancement. –  Peter Grill Oct 2 '12 at 9:20
@Luigi: Thanks, those were the options I was looking for. I just couldn't find them in the manual (always hard to search for something when english is not your first language). –  Janek Oct 4 '12 at 9:07
@Peter Grill: Thanks for the advice, labels were chosen arbitrarily for this MWE though. Usually, I use the same format for the labels as I use in the text/formulas which is, in fact, usually the math mode. Still a valid statement and nice to see, that people do pay attention :) –  Janek Oct 4 '12 at 9:12