我一直尝试使用 TiKZ 制作一组条形图,pgfplots
但由于某些未知原因,即使图形中没有添加网格,该图也会在 X = 1 中显示垂直网格。
有办法解决这个问题吗? 这是一个 MWE:
\documentclass{article}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin = 0, xmax = 4,
ymin = 0, ymax = 0.2,
yticklabel={\pgfmathparse{\tick*100}\pgfmathprintnumber{\pgfmathresult}\%},
xlabel = X, ylabel = Y,
ybar interval=1,
bar width=25pt,
legend style={cells={anchor=center, fill}, nodes={inner sep=1,below=-1.1ex}},area legend,
legend pos=outer north east
]
\addplot [color = red, fill = red, ybar]
coordinates{(1,0.1632003)
};
\addplot [color = green, fill = green, ybar]
coordinates{(2,0.132558)
};
\addplot [color = blue, fill = blue, ybar]
coordinates{(3,0.1173594)
};
\draw [black, thick] (axis cs:0,0) -- (axis cs:7,0);
\legend{A, B, C}
\end{axis}
\end{tikzpicture}
\end{document}
预览:
答案1
ybar interval
需要至少两个坐标来绘制间隔。但随后您又切换回ybar
。因此参考线宽度为零ybar interval
。