我正在尝试使用 pgfplots 包创建一个 xbar 图。但这些条形图彼此不成比例。这是一个最简单的示例:
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
y axis line style = { opacity = 0 },
axis x line = none,
tickwidth = 0pt,
ytick={1,2},
yticklabels={1,2},
xbar,
nodes near coords,
nodes near coords align={horizontal}
]
\addplot coordinates {
(1000,2)
(500,1)
};
\end{axis}
\end{tikzpicture}
\end{document}
如果我将值 1 改为 1,000,它们的大小相同。但是,如果值是 2 的一半,为什么条形图的大小不是 2 的一半?
答案1
您应该添加xmin=0
:
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
y axis line style = { opacity = 0 },
axis x line = none,
tickwidth = 0pt,
ytick={1,2},
yticklabels={1,2},
xbar,
nodes near coords,
nodes near coords align={horizontal},
xmin = 0
]
\addplot coordinates {
(1000,2)
(500,1)
};
\end{axis}
\end{tikzpicture}
\end{document}