![停用 ybar 以使用 ybar 堆叠](https://linux22.com/image/365980/%E5%81%9C%E7%94%A8%20ybar%20%E4%BB%A5%E4%BD%BF%E7%94%A8%20ybar%20%E5%A0%86%E5%8F%A0.png)
我有一个模板可以全局设置ybar
选项。但是,我想使用ybar stacked
。当结合两者时,输出栏会向右移动,如下例所示。如何在ybar
不将其从全局选项中删除的情况下重置效果?
这个问题非常类似于这个帖子,但事实却恰恰相反。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{ybar} % global option that can not be removed
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar stacked]
\addplot coordinates {(0,1) (1,1) (2,3) (3,2) (4,1.5)};
\addplot coordinates {(0,1) (1,1) (2,3) (3,2) (4,1.5)};
\addplot coordinates {(0,1) (1,1) (2,3) (3,2) (4,1.5)};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
添加bar shift=0pt
到轴选项:
\begin{axis}[ybar stacked,bar shift=0pt]
compat
补充说明:加载后立即设置pgfplots
。
代码:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}% <- add this after loading pgfplots, current version is 1.15
\pgfplotsset{ybar} % global option that can not be removed
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar stacked,
bar shift=0pt% <- added
]
\addplot coordinates {(0,1) (1,1) (2,3) (3,2) (4,1.5)};
\addplot coordinates {(0,1) (1,1) (2,3) (3,2) (4,1.5)};
\addplot coordinates {(0,1) (1,1) (2,3) (3,2) (4,1.5)};
\end{axis}
\end{tikzpicture}
\end{document}