3

I want to set different lower and upper deviations for error bars. It seems that PGFplots does not support unequal +,- error bar length. I have come up with a solution, that is to draw + and - error bars separately on the same axis. In this case the legend does not show correctly.

Is there any other way to plot unequal error bars without having to re-plot the data? Or is there anyway I can fix the legend probelm?

\documentclass{book} \usepackage{pgfplots} \pgfplotsset{compat=1.3} \begin{document} \begin{figure} \centering \begin{tikzpicture} \begin{axis} \addplot+[error bars/.cd, y dir=both,y explicit] coordinates { (0,0) +- (0.5,0.1) (0.1,0.1) +- (0.05,0.2) (0.2,0.2) +- (0,0.05) (0.5,0.5) +- (0.1,0.2) (1,1) +- (0.3,0.1)}; \end{axis} \end{tikzpicture} \begin{tikzpicture} \begin{axis} \addplot[mark=*,blue] plot[error bars/.cd, y dir=plus,y explicit] coordinates { (0,0) +- (0.5,0.1) (0.1,0.1) +- (0.05,0.2) (0.2,0.2) +- (0,0.05) (0.5,0.5) +- (0.1,0.2) (1,1) +- (0.3,0.1)}; \addlegendentry{first plot} \addplot[mark=*,blue] plot[error bars/.cd, y dir=minus,y explicit] coordinates { (0,0) +- (0.5,0.2) (0.1,0.1) +- (0.05,0.1) (0.2,0.2) +- (0,0.1) (0.5,0.5) +- (0.1,0.5) (1,1) +- (0.3,0.4)}; \addplot[mark=x,red] plot[error bars/.cd, y dir=plus,y explicit] coordinates { (1,0) +- (0.5,0.1) (1.1,0.1) +- (0.05,0.2) (1.2,0.2) +- (0,0.05) (1.5,0.5) +- (0.1,0.2) (2,1) +- (0.3,0.1)}; \addlegendentry{second plot} \addplot[mark=none,red] plot[error bars/.cd, y dir=minus,y explicit] coordinates { (1,0) +- (0.5,0.2) (1.1,0.1) +- (0.05,0.1) (1.2,0.2) +- (0,0.1) (1.5,0.5) +- (0.1,0.5) (2,1) +- (0.3,0.4)}; \end{axis} \end{tikzpicture} \end{figure} \end{document} 

enter image description here

5
  • 1
    The upcoming version 1.9 of pgfplots comes with native support for asymmetric error bars. Sneak previews are available at pgfplots.sourceforge.net Commented Sep 28, 2013 at 7:25
  • \begin{axis}[ymax = 1.5] will fix your legend. Commented Sep 28, 2013 at 16:14
  • 1
    You will also need to reorder the plots. \addlegendtry depends only on the order in which they occur, not where they occur. So do all the positive error bars in order, then go back and do the negative error bars. Commented Sep 29, 2013 at 16:29
  • @ChristianFeuersänger, It is great! Though I couldn't find how to use asymmetric error bars in the pgfplots manual or the gallery. How to use asymmetric error bars in version 1.9 of pgfplots? Commented Nov 22, 2013 at 5:43
  • The section "Input Formats of Error Coordinates" covers contains examples for both \addplot coordinates (search for the syntax -= and +=) and \addplot table. Commented Nov 23, 2013 at 19:29

1 Answer 1

3

You can use \drawplot option "forget plot" to keep the second plot (lower error bars) from appearing in the legend.

\addplot[mark=*,blue,forget plot] plot[error bars/.cd, y dir=minus,y explicit] coordinates { (0,0) +- (0.5,0.2) (0.1,0.1) +- (0.05,0.1) (0.2,0.2) +- (0,0.1) (0.5,0.5) +- (0.1,0.5) (1,1) +- (0.3,0.4)}; 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.