Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've created a bar chart with labels for the x coordinates. But if I don't put a xmin/xmax in, only half of the first and last bar appear. If I add a xmax it shows up on the axis.

\begin{figure}[h!]
\small
\begin{tikzpicture}
\begin{axis}[%
width=3.5in,
height=1.5in,
axis x line=center,
axis y line=left,
symbolic x  coords={0,Choice1,Choice2 Here,Choice3 Here,Choice4 Goes Here,Last Choice, 1},
ymin=0, ymax=2,
xmin=0, xmax=1,
nodes near coords,
ylabel style={align=center},
ylabel={Mean days\\per month},
x tick label style={font=\small,text width=1cm,align=center},
ybar]


\addplot[color=blue,fill] coordinates {(Choice1,0.6)(Choice2 Here,0.1) (Choice3 Here,1.6)};
\addplot[color=black,shade] coordinates {(Choice4 Goes Here,0.9) (Last Choice,0.9)};

\end{axis}
\end{tikzpicture}
\end{figure}

Bar chart

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Instead of setting all values for xmin, ymin, xmax, ymax, use enlargelimits=true:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{figure}
\small
\begin{tikzpicture}
\begin{axis}[%
width=3.5in,
height=1.5in,
axis x line=center,
axis y line=left,
symbolic x  coords={Choice1,Choice2 Here,Choice3 Here,Choice4 Goes Here,Last Choice},
enlargelimits=true,
ymin=0,
nodes near coords,
ylabel style={align=center},
ylabel={Mean days\\per month},
x tick label style={font=\small,text width=1cm,align=center},
ybar]


\addplot[color=blue,fill] coordinates {(Choice1,0.6) (Choice2 Here,0.1) (Choice3 Here,1.6)};
\addplot[color=black,shade] coordinates {(Choice4 Goes Here,0.9) (Last Choice,0.9)};

\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}

enter image description here

As Jake has suggested in a comment, with bar charts it is advisable to include the origin in the axis range explicitly (in this case by using ymin=0 in addition to enlargelimits).

As a side note, I'd suggest you not to use the too restrictive [!h] option for float placement; use a less restrictive one or don't use any at all.

share|improve this answer
    
The enlargelimits=true fixed the problem. I will also take your recommendations to further improve the image. –  user2433701 Sep 17 '13 at 13:15
1  
@Jake I've incorporated your suggestion to my answer. Thanks! –  Gonzalo Medina Sep 17 '13 at 13:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.