Formatieren von Balkendiagrammen pgfplots

Formatieren von Balkendiagrammen pgfplots

Wie kann ich die gesamten Balken anzeigen und die Y-Achse in beide Richtungen (oben und unten) leicht erweitern?

\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}

Bildbeschreibung hier eingeben

Antwort1

Ja. Sie können die y-Grenzen mit vergrößern 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}

Bildbeschreibung hier eingeben

verwandte Informationen