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'm using pgfplots to produce a plot of a closed path in the x-y plane. For reasons that are not important here, I would like to fill the closed path. That works fine, but the axes are then hidden by the filled path. How can I push the filled path into the background or the axes into the foreground? I looked at some other questions here that mention using pgflayers, but I can't find that in either the TikZ or pgfplots manuals.

MWE:

\documentclass[10pt]{article}

\usepackage{tikz}
\usepackage{fancyhdr}
\usepackage{pgfplots}

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}
\thispagestyle{empty}

\begin{tikzpicture}
\begin{axis}[
  axis x line=middle,
  axis y line=middle,
  xmin = -2.0, xmax =  2.0,
  ymin = -2.0, ymax =  2.0,
]
\addplot[fill=lightgray,mark=none] coordinates {
  (-1.0, -1.0)
  ( 1.0, -1.0)
  ( 1.0,  1.0)
  (-1.0,  1.0)
  (-1.0, -1.0)
}; 
\end{axis}
\end{tikzpicture}

\end{document}
share|improve this question

1 Answer 1

up vote 4 down vote accepted

There's a key for the axis environemnt

axis on top

which gives

enter image description here

\documentclass[10pt]{article}

\usepackage{pgfplots}

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}
\thispagestyle{empty}

\begin{tikzpicture}
\begin{axis}[axis on top,
  axis x line=middle,
  axis y line=middle,
  xmin = -2.0, xmax =  2.0,
  ymin = -2.0, ymax =  2.0,
]
\addplot[fill=lightgray,mark=none] coordinates {
  (-1.0, -1.0)
  ( 1.0, -1.0)
  ( 1.0,  1.0)
  (-1.0,  1.0)
  (-1.0, -1.0)
}; 
\end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer
    
I know, but I want to avoid that so this plot is consistent in style with other, TikZ-generated, plots in which I do not use opacity. –  user1362373 Mar 20 '12 at 17:43
    
Great - I don't know how I missed that option. Thanks a lot. –  user1362373 Mar 20 '12 at 18:55

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.