我正在尝试创建一个从最小值到最大值的条形图,并带有一条平均线。到目前为止,我有一条带有最小值、最大值和平均值的线,但我希望条形更宽。有什么办法吗?
\pgfplotstableread{
x y y-max y-min
AfterCoffee 17.62 26.566667 9.0
BeforeCoffee 14.42 23.0333333 8.683333
}{\mytable}
\begin{tikzpicture}[scale=1.3]
\begin{axis} [
width = 0.5*\textwidth,
height = 8cm,
symbolic x coords={AfterCoffee,BeforeCoffee},
xtick=data
]
\addplot+[blue, very thick, forget plot,only marks]
plot[very thick, error bars/.cd, y dir=plus, y explicit]
table[x=x,y=y,y error expr=\thisrow{y-max}] {\mytable};
\addplot+[red, very thick, only marks,xticklabels=\empty]
plot[very thick, error bars/.cd, y dir=minus, y explicit]
table[x=x,y=y,y error expr=\thisrow{y-min}] {\mytable};
\end{axis}
\end{tikzpicture}
答案1
您可以使用 控制误差线的格式every error bar
。
只需添加
\pgfplotsset{every error bar/.style={line width=1mm}}
或者
\pgfplotsset{every error bar/.style={ultra thick}}
代码
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotsset{every error bar/.style={line width=1mm}}
\pgfplotstableread{
x y y-max y-min
AfterCoffee 17.62 26.566667 9.0
BeforeCoffee 14.42 23.0333333 8.683333
}{\mytable}
\begin{tikzpicture}[scale=1.3]
\begin{axis} [
width = 0.5*\textwidth,
height = 8cm,
symbolic x coords={AfterCoffee,BeforeCoffee},
xtick=data
]
\addplot+[blue, very thick, forget plot,only marks]
plot[very thick, error bars/.cd, y dir=plus, y explicit]
table[x=x,y=y,y error expr=\thisrow{y-max}] {\mytable};
\addplot+[red, very thick, only marks,xticklabels=\empty]
plot[very thick, error bars/.cd, y dir=minus, y explicit]
table[x=x,y=y,y error expr=\thisrow{y-min}] {\mytable};
\end{axis}
\end{tikzpicture}
\end{document}