我想制作一个pgfplots
ybar interval
情节,间隔延伸到左边标记点。
这是一个最小的非工作示例:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0,xmax=5,
ymin=0,ymax=1
]
\addplot+[ybar interval,fill=blue!50] coordinates {(1,1) (2,0.25) (3,0.11111) (4,0.0625) (5,0.04)};
\end{axis}
\end{tikzpicture}
\end{document}
如您所见,间隔向右延伸。我宁愿它看起来像这样:
而不必这样做(我如何制作上述内容):
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0,xmax=5,
ymin=0,ymax=1
]
\addplot+[ybar interval,forget plot,fill=blue!50,mark=none] coordinates {(0,1) (1,0.25) (2,0.11111) (3,0.0625) (4,0.04) (5,0)};
\addplot+[only marks] coordinates {(1,1) (2,0.25) (3,0.11111) (4,0.0625) (5,0.04)};
\end{axis}
\end{tikzpicture}
\end{document}
是否有我可以设置的密钥,或者其他更简洁的方法来获得我想要的东西?
答案1
由于所有条形的宽度都相同,因此没有必要使用ybar interval
。相反,您可以使用ybar, bar width=1, bar shift=-0.5
(这需要\pgfplotsset{compat=1.8}
或更大)。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0,xmax=5,
ymin=0,ymax=1,
bar width=1,
bar shift=-0.5
]
\addplot+[ybar,fill=blue!50] coordinates {(1,1) (2,0.25) (3,0.11111) (4,0.0625) (5,0.04)};
\end{axis}
\end{tikzpicture}
\end{document}