pgf-tikz / pgfplots

pgfplots - A TeX package to draw normal and/or logarithmic plots directly in TeX in two and three dimensions with a user-friendly interface and pgfplotstable - a TeX package to round and format numerical tables. Examples in manuals and/or on web site.
http://pgfplots.sourceforge.net/
198 stars 33 forks source link

Propose to simplification of error bars formatting. #372

Open mmarras opened 4 years ago

mmarras commented 4 years ago

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 via error bar mark options and the hypothetical error bar stem options or something of that sort.

muzimuzhi commented 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.

https://github.com/pgf-tikz/pgfplots/blob/324e29dbdf7cd21dccaff201e35ffdb0558c43c0/tex/generic/pgfplots/pgfplots.code.tex#L3147-L3150

\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}

image

muzimuzhi commented 4 years ago

Related TeX-SX question: https://tex.stackexchange.com/questions/562180/formatting-error-bar-mark-pgfplots-append-to-style.