我在 pdflatex 中使用 PGFPlots,我试图将 y 轴的最小值设置为 0。但是,当我使用该ymin=0
命令时,图表底部、条形图和标签之间出现了间隙。
有什么办法可以解决这个问题吗?我尝试设置enlargelimts = false
,但是当我这样做时,最左边和最右边的条形图会被分成两半。
\begin{axis}[
ybar,
enlargelimits=0.1,
ylabel={\%},
symbolic x coords={Bar1, Bar2, Bar3, Bar4, Bar5},
xtick=data,
xticklabel style = {rotate=60,anchor=east},
enlargelimits = true,
grid,
ytick={0,20,40,60,80,100},
ymin=0,
width=10cm,
bar width =1cm,
]
\addplot[black,fill=lightgray] coordinates {(Bar1,50) (Bar2,60) (Bar3,50) (Bar4,75) (Bar5,80)};
\end{axis}
答案1
从我的上述评论。您有enlargelimits=0.1,
和enlargelimits=true,
但您似乎只想放大x limits
。
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
enlarge x limits=0.1,
ylabel={\%},
symbolic x coords={Bar1, Bar2, Bar3, Bar4, Bar5},
xtick=data,
xticklabel style = {rotate=60,anchor=east},
enlarge y limits =false,
grid,
ytick={0,20,40,60,80,100},
ymin=0,ymax=90,
width=10cm,
bar width =1cm,
]
\addplot[black,fill=lightgray] coordinates {(Bar1,50) (Bar2,60) (Bar3,50) (Bar4,75) (Bar5,80)};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
enlargelimits = true
用。。。来代替enlarge x limits = true, enlarge y limits = upper
。