格式化条形图 pgfplots

格式化条形图 pgfplots

如何显示整个条形图并稍微在两个方向(顶部和底部)延伸 y 轴?

\documentclass{standalone}
   \usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            xbar,
            xmin = 0,
            y = 35pt,
            bar width= 2em,
            axis x line       = none,
            axis y line       = left,
            tickwidth         = 0pt,
            symbolic y coords = {A,B,C,D},
            nodes near coords,
          ]
          \addplot coordinates { (45,A) (55,B) (40,C) (50,D) };
         \end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

是的。您可以使用 扩大 y 限制enlarge y limits

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            xbar,
            xmin = 0,
            y = 35pt,
            bar width= 2em,
            axis x line       = none,
            axis y line       = left,
            tickwidth         = 0pt,
            symbolic y coords = {A,B,C,D},
            nodes near coords,enlarge y limits=0.2
          ]
          \addplot coordinates { (45,A) (55,B) (40,C) (50,D) };
         \end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容