Open mmarras opened 4 years ago
Considering the compatibility issues, changing the behavior of existing keys is harder than adding new keys. From how keys error mark options
and error bar style
, which influence the mark and "stem" of error bar respectively, are defined, in the following example a new key error mark and bar options
is provided. It appends its value to both those two keys.
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\pgfkeys{
% appends value to both "error mark options" and "error bar style"
/pgfplots/error bars/error mark and bar options/.code={%
\pgfkeysalso{
/pgfplots/error bars/error mark options/.append={,#1},
/pgfplots/every error bar/.append style={#1}
}%
}
}
\begin{tikzpicture}
% based on the example in doc of key "error bars/x explicit relative"
\begin{loglogaxis}
\addplot+ [
error bars/.cd,
x dir=both,x fixed relative=0.5,
y dir=both,y explicit relative,
error mark and bar options={line width=1pt, blue!25}
] table [x=x,y=y,y error=error] {
x y error
32 32 0
64 64 0
128 128 0.3
1024 1024 0.2
32068 32068 0.6
64000 64000 0.6
128000 128000 0.6
};
\end{loglogaxis}
\end{tikzpicture}
\end{document}
Related TeX-SX question: https://tex.stackexchange.com/questions/562180/formatting-error-bar-mark-pgfplots-append-to-style.
I find the design choice of the error bar styles a bit cumbersome. I would argue the most common change that needs to be done to the error bar is changing thickness. It's just my impression, but so far I have seen mostly examples, where the stem and the mark have the same thickness, so that seems to be the default for most people - myself included. Changing thickness, however, involves two commands one for the vertical and one for the horizontal portion of the error bar. Why is there is no high-level command to change the style of the vertical and horizontal portion of the error bars at the same time? But rather they need to be changed individually.
Maybe a suggestion, it would be nice to combine the styles and make it the default behaviour to change both by using
error bar style
, then make the styles individually accessible viaerror bar mark options
and the hypotheticalerror bar stem options
or something of that sort.