PGFplots 误差线中上下偏差不一致的图例!

PGFplots 误差线中上下偏差不一致的图例!

我想为误差线设置不同的下限和上限偏差。似乎PGFplots不支持不相等的 +、- 误差线长度。我想出了一个解决方案,即在同一轴上分别绘制 + 和 - 误差线。在这种情况下,图例无法正确显示。

有没有其他方法可以绘制不等误差线,而不必重新绘制数据?或者有什么方法可以修复图例问题?

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

在此处输入图片描述

答案1

您可以使用 \drawplot 选项“忘记图”来阻止第二个图(较低的误差线)出现在图例中。

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

相关内容