# formatting bar charts pgfplots

How to show the entire bars and slightly extend the y axis in both directions (top and bottom)?

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


Yes. You can enlarge the y limits with 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}


• Do you know why if enlarge y limits=0.2, is inserted before, for example between xmin = 0 and y = 35pt, this key doesn't have the expected effect? I don't find in the manual a such restriction. Mar 17 '19 at 4:27
• @quark67 On p. 329 it is written that "Specifying a number value like ‘enlarge x limits=0.2’ will enlarge lower and upper axis limit rela- tively. The following example adds 20% of the axis limits on both sides:" and I think the analogous statement applies to enlarge y limits.
– user121799
Mar 17 '19 at 4:57
• I speak about the position of the key enlarge y limits. You add it after nodes near coords. But if you move it between for example, xmin = 0 and y = 35pt, it seems don’t have any effect (ie: it gave the same output as the OP screenshot). Is this behavior only on my installation? Mar 17 '19 at 5:10
• Thank marmot. I tried this before, but as @quark67 said I was placing it just after y = 35pt and it was not working. Mar 17 '19 at 13:47