# Change y range at symbolic y coords

I have the following tikz code

\begin{tikzpicture}
\begin{axis}[
xbar,
y axis line style = {opacity = 0},
axis x line       = none,
tickwidth         = 0pt,
enlarge y limits  = 1.8,
legend style={at={(0.91,0.8)},anchor=east},
symbolic y coords = {2016,2009},
ytick             = data,
nodes near coords
]

\addplot [color=black,fill=red]  coordinates { (8518,2009)     (10891,2016) };
\addplot [color=black,fill=blue] coordinates { (5827,2009)     (5845,2016)  };

\legend{DEB,LMR}
\end{axis}
\end{tikzpicture}


which gives me this:

The tiikz plot is included into my main .tex file via

 \begin{figure}[!htb]
\centering
\input{barchart.tex}
\caption{Here is the description of the plot}
\label{fig:barchartplot}
\end{figure}


However, there is much empty space above and below the bars. How can I "clip" this image? Above and below there is much text and I dont want to have so much "white area" around the image!

Thanks an advance for you help!

André

The default bar width is 10pt and the sep between two bars at the same y-value is 2pt (xbar=2pt is default). You have two plots and so the space needed between 2009 and 2016 is at least (2*10pt+2pt)+2pt=24pt. So you can use

y=30pt,
enlarge y limits={abs=15pt}% the value must be at least half of y


Then you have to remove enlarge y limits = 1.8 and to change the legend style. One possibility is

legend style={at={(1,1-|{axis cs:10891,2016})},anchor=north east},


Another

legend style={at={(1,1-|{axis cs:10891,2016})},anchor=south east},


There are other possibilities too.

Code:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
y=30pt,
enlarge y limits={abs=15pt},
xbar,
y axis line style = {opacity = 0},
axis x line       = none,
tickwidth         = 0pt,
%legend style={at={(1,1-|{axis cs:10891,2016})},anchor=north east},
legend style={at={(1,1-|{axis cs:10891,2016})},anchor=south east},
symbolic y coords = {2016,2009},
ytick             = data,
nodes near coords
]

\addplot [color=black,fill=red]  coordinates { (8518,2009)     (10891,2016) };
\addplot [color=black,fill=blue] coordinates { (5827,2009)     (5845,2016)  };

\legend{DEB,LMR}
\end{axis}
\end{tikzpicture}
\end{document}

• This is exactly what I wanted! Thanks for the great explaination, working like a charm! :-) – AndreH Jul 20 '16 at 15:54