I'm trying to visualize some data with bar graphs. Some of those bar graphs work fine and some (with the same code, just different data points) have the bars "floating above the x-axis". This bar graph works fine:
\begin{tikzpicture}
\begin{axis}[
ybar,
bar width=40,
enlarge x limits=0.3,
legend style={at={(0.5,-0.2)},
anchor=north,legend columns=-1},
ylabel={\# Participants},
symbolic x coords={no limit,unclear},
xtick=data,
nodes near coords,
]
\addplot coordinates {(no limit,17) (unclear,5)};
\end{axis}
\end{tikzpicture}
And this one has a distance between the onset of the bars and the x-axis that I would like to eliminate:
\begin{tikzpicture}
\begin{axis}[
ybar,
bar width=40,
enlarge x limits=0.3,
legend style={at={(0.5,-0.2)},
anchor=north,legend columns=-1},
ylabel={\# Participants},
symbolic x coords={x-10,other},
xtick=data,
nodes near coords,
]
\addplot coordinates {(x-10,22) (other,0)};
\end{axis}
\end{tikzpicture}
I found different similar questions on tex-exchange, but the solutions don't seem to apply: I don't have an "enlarge y limits"-factor, and one solution mentioned setting ymin=0 as an argument in axis, which didn't change anything.
Best Answer
While @percusse has given you a working solution for graph 2,
ymin=0
also works, but I note you said it didn't work for you. There must be a difference between what I have posted below and what you tested. You can also useymin=0
in the second graph, if I have interpreted the problem correctly.This is the code, only very slightly modified from your version by adding
ymin=0,
. By the way, it is always best to post full, compilable minimum working examples, inclusive of document class, the minimum packages and libraries that you are using.