The following MWE shows two bar plots with error bars.
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\pgfplotstableread{
x y1 y1_err y2 y2_err
0 1 .1 2 .2
1 2 .2 3 .3
2 3 .3 4 .4
}\loadedtable
\begin{tikzpicture}
\begin{axis}[ybar,bar width=14pt ]
\addplot[
style={red, fill=red},
error bars/.cd,
error bar style={
thick,
},
y dir=both,
y explicit,
] table[
x=x,
y=y1,
y error=y1_err,
] {\loadedtable};
\addplot[
style={blue, fill=blue},
error bars/.cd,
error bar style={
thick,
},
y dir=both,
y explicit,
]
table[x=x, y=y2, y error=y2_err] {\loadedtable};
\end{axis}
\end{tikzpicture}
\end{document}
One of the downsides is that I have to repeat a lot of the same error-bar style code, whereas I would ideally like to be able to do something like:
\pgfplotsset{errorBars/.style={
error bars/.cd,
error bar style={
thick,
},
y dir=both,
y explicit,
}
}
Unfortunately, \addplot[errorBars/.style,style={red, fill=red}]
does not actually show the error bars as desired.
How can I set the style for all error bars in one particular tikzpicture?