我有一个模板可以全局设置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}