我是 pgfplots 的新手,但它似乎是一个非常有用的包。不过,我不太明白如何使用误差线。
下面是我的柱形图的代码,其中有些列应该包含误差线。我发现我需要对误差线使用不同的 \addplot 命令,但它们仍然没有显示。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width = 0.85*\textwidth,
height = 8cm,
major x tick style = transparent,
ybar=2*\pgflinewidth,
bar width=14pt,
ymajorgrids = true,
ylabel = {Concentration [mg/L]},
symbolic x coords={1,2,3,4},
xtick = data,
scaled y ticks = false,
enlarge x limits=0.25,
ymin=0,
legend cell align=left,
legend style={
at={(1,-0.40)},
anchor=south east,
column sep=1ex
}
]
\addplot+[error bars/.cd,,addplot[y dir=both,y explicit]
coordinates {
(1, 133.1)
(2,251.7)
(3,372.4)
(4,517.9)
};
\addplot+[error bars/.cd,,addplot[y dir=both,y explicit]
coordinates {
(1,97.4) +- (0.0, 11.0)
(2,175.5) +- (0.0, 3.86)
(3,290.8) +- (0.0, 3.14)
(4,482.8) +- (0.0, 15.3)
};
\addplot+[error bars/.cd,,addplot[y dir=both,y explicit]
coordinates {
(1,116.9)
(2,150.2) +- (0.0, 0.56)
(3,289.0) +- (0.0, 13.2)
(4,429.6) +- (0.0, 29.0)
};
\legend{Untreated solution,Treated with A,Treated with B}
\end{axis}
\end{tikzpicture}
\end{document}
有人知道为什么这不起作用吗?是不是我的 \begin{axis} 设置中有什么东西阻止它们显示?
提前致谢!
答案1
如果我不嵌套addplot
,我会得到
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width = 0.85*\textwidth,
height = 8cm,
major x tick style = transparent,
ybar=2*\pgflinewidth,
bar width=14pt,
ymajorgrids = true,
ylabel = {Concentration [mg/L]},
symbolic x coords={1,2,3,4},
xtick = data,
scaled y ticks = false,
enlarge x limits=0.25,
ymin=0,
legend cell align=left,
legend style={
at={(1,-0.40)},
anchor=south east,
column sep=1ex
}
]
\addplot+[error bars/.cd,y dir=both,y explicit]
coordinates {
(1, 133.1)
(2,251.7)
(3,372.4)
(4,517.9)
};
\addplot+[error bars/.cd,y dir=both,y explicit]
coordinates {
(1,97.4) +- (0.0, 11.0)
(2,175.5) +- (0.0, 3.86)
(3,290.8) +- (0.0, 3.14)
(4,482.8) +- (0.0, 15.3)
};
\addplot+[error bars/.cd,y dir=both,y explicit]
coordinates {
(1,116.9)
(2,150.2) +- (0.0, 0.56)
(3,289.0) +- (0.0, 13.2)
(4,429.6) +- (0.0, 29.0)
};
\legend{Untreated solution,Treated with A,Treated with B}
\end{axis}
\end{tikzpicture}
\end{document}
即,误差线会出现+-
在数据中的任何地方。