[Tex/LaTex] No content in zoom Tikz spy

spytikz-pgf

I'm trying to use the spy glass in Tikz, but for some reason my zoom area is always empty and (some) graphs tend to disappear when I use spy. I've updated all my packages etc. through the updater by MikTeX but this didn't solve anything. The code I use:

\documentclass{article} 
\usepackage{pgfplots} 
\usetikzlibrary{spy} 

\begin{document}  
\begin{tikzpicture}
[spy using outlines={rectangle, magnification=3,connect spies}] 

\begin{axis}[grid=major,no markers,domain=-5:5,enlargelimits=false] 
    \addplot[solid,mark=asterisk,mark options={solid},color=blue] {x^2};
    \addplot[solid,mark=asterisk,mark options={solid},color=red] {x^3};  
    \addplot[only marks,mark=star,mark size=2pt,color=black] coordinates{(0,0)};
    \coordinate (spypoint) at (axis cs:0,0); 
    \coordinate (spyviewer) at (axis cs:0.5,-90); 
\end{axis}  
    \spy[width=6cm,height=1cm] on (spypoint) in node [fill=white] at (spyviewer); 

\end{tikzpicture}  

\begin{tikzpicture}
%[spy using outlines={rectangle, magnification=3,connect spies}] 

\begin{axis}[grid=major,no markers,domain=-5:5,enlargelimits=false] 
    \addplot[solid,mark=asterisk,mark options={solid},color=blue] {x^2};
    \addplot[solid,mark=asterisk,mark options={solid},color=red] {x^3};  
    \addplot[only marks,mark=star,mark size=2pt,color=black] coordinates{(0,0)};
    %\coordinate (spypoint) at (axis cs:0,0); 
    %\coordinate (spyviewer) at (axis cs:0.5,-90); 
\end{axis}  
    %\spy[width=6cm,height=1cm] on (spypoint) in node [fill=white] at (spyviewer); 

\end{tikzpicture}  
\end{document}

I'm not allowed to upload an image here since I'm new, but the red and blue graphs disappear with the spy glass, where the black dot remains. The areas of the spy glass are correct, but also the black dot doesn't appear in the zoom area, it's completely empty. When not using spy, the graphs appear perfectly fine…

Best Answer

Ok, that was enough info to sort of track down what is going on. There was a bug in the spy library that caused it to fail with dvips or xelatex. This was reported and apparently fixed here, but I don't think there's actually been a release of pgf/tikz since then, at least not one that is showing up on sourceforge, so updating the tex installation wouldn't help.

You could try subbing in the newest version of this library to your pgf installation (source code here). However I tried doing this and it didn't quite work, though it behaved differently than the buggy behavior (which, incidentally, I was able to replicate) -- the spy part worked but the plot part didn't. Possibly I was doing something wrong and I didn't try very hard. But probably you would need to install the development version of the whole package to fix this bug in the meantime, rather than just updating this one file. Or give up on .ps as you say :).