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 been trying to plot an xbar graph using pgfplots within a tikzpicture. I want to be able to only show the yaxis on the left and the x axis on the bottom. When I set axis y line=left and axis x line=bottom though, I get arrows on the axis. Is it possible to remove them? Also, I can't seem to control the spacing of the bar plots, is that possible? I'd like them to be much closer together then they are currently. Here's my attempt so far:

\begin{tikzpicture}
  \begin{axis}[
    xbar,
    symbolic y coords={4 Sep 11,4 Oct 11,4 Nov 11},
    width=0.4\textwidth,
    height=0.15\textheight,
    nodes near coords={\$\pgfmathprintnumber\pgfplotspointmeta},
    nodes near coords align={horizontal},
    xtick=\empty,
    axis x line=bottom,
    axis y line=left,
    xmin=0,
    bar width=12pt,
    enlarge limits=0.2,
  ]
  \addplot[fill=blue]
    coordinates {(121.28,4 Nov 11) (100.00,4 Oct 11) (50.00,4 Sep 11)};
  \end{axis}
\end{tikzpicture}

The output of which is:

enter image description here

Things I have tried: enlarge limits (If I enable it, the plot looks a bit nicer), xbar interval and shrinking the height of the plot to no avail. I'm a little stumped at the moment.

share|improve this question

1 Answer 1

up vote 7 down vote accepted

Use the starred version of these options. Regarding the distance between the bars you should increase the height of the plot.

\documentclass{minimal}
\usepackage{pgfplots}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[%
      xbar,
      symbolic y coords={4 Sep 11,4 Oct 11,4 Nov 11},
      width=0.4\textwidth,
      height=0.25\textheight,
      nodes near coords={\$\pgfmathprintnumber\pgfplotspointmeta},
      nodes near coords align={horizontal},
      xtick=\empty,
      axis x line*=bottom,
      axis y line*=left,
      xmin=0,
      bar width=12pt,
      enlargelimits=0.2,
    ]
      \addplot[fill=blue] coordinates {(121.28,4 Nov 11) (100.00,4 Oct 11) (50.00,4 Sep 11)};
    \end{axis}
  \end{tikzpicture}  
\end{document}

Details in the pgfplots manual

share|improve this answer
1  
Oh boy, that was awesome -- everything's working! The starred versions got rid of the arrows. enlargelimits=0.2 caused the x limits to change also so I used enlarge y limits=0.2 and that did the job perfectly. As for the spacing, it seems to be much better. Thanks! –  slurms Nov 8 '11 at 16:17
1  
@slurms: I would recommend you set enlarge x limits={upper, value=0.2}. That way, only the upper limit is moved, so the bars still start at the y axis. –  Jake Nov 8 '11 at 20:48

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.