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.

How can I go about putting a grid in front of a bar chart in PGFPlots, preferably as automagically as possible? Ed Tufte demonstrates a rather appealing way of drawing bar charts in The Visual Display of Quantitative Information that consists of removing horizontal grid lines from the bars (example centre), and it occurs to me that this can be replicated by drawing white horizontal lines over the chart, or perhaps through some other route.

Any ideas?

share|improve this question
    
Perhaps this would help? tex.stackexchange.com/questions/9559/… –  Martin Tapankov Mar 10 '11 at 6:12
    
Good suggestion, however unfortunately it doesn't. help lines can indeed be made to draw on top of the chart, however their spacing has no correspondence to the PGFPlots coordinate system of the chart. –  Richard Terrett Mar 10 '11 at 6:19
add comment

1 Answer

up vote 8 down vote accepted

There's an axis on top for the axis environment that can be used to achieve what you asked for:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar,
  xtick=data,
  ymin=0,
  axis lines*=left,
  axis on top,
  ymajorgrids=true,
  grid style={white}]
\addplot [fill=black] coordinates { (0,2) (1,1.5) (2,3)};
\addplot [draw=black!40,fill=black!40] coordinates { (0,2.2) (1,1.1) (2,5.1)};
\end{axis}
\end{tikzpicture}
\end{document}

bar chart with y grid on top

share|improve this answer
    
Perfect, exactly what I was looking for. Thank you. –  Richard Terrett Mar 10 '11 at 6:21
add comment

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.