`spy` breaks `grid` and `fill between`
Brought to you by:
cfeuersaenger,
ludewich
When I add a spy the grid as well as the fill between path get broken and are not drawn any more.
\documentclass{standalone} \usepackage{tikz} \usepackage{pgfplots} \usetikzlibrary{ spy, pgfplots.fillbetween, } \pgfplotsset{compat=1.13} \begin{document} \begin{tikzpicture}[ spy using outlines={ circle, magnification=4, size=2cm, connect spies, }, ] \begin{axis}[ xmin=0, xmax=7, ymin=0, ymax=30, grid=major, ] \addplot+[name path=A,domain=0:6] {x^2}; \path[name path=B] (\pgfkeysvalueof{/pgfplots/xmin},0) -- (\pgfkeysvalueof{/pgfplots/xmax},0); \addplot[red!10] fill between [of=A and B, soft clip={domain=1:5}]; \coordinate (point to spy) at (1,0); \coordinate (show magnification) at (2,20); \end{axis} % uncomment me to show the bug(s) % \spy [red] on (point to spy) % in node [fill=white] at (show magnification); \end{tikzpicture} \end{document}
This bug can now also be found on TeX.SX:
- https://tex.stackexchange.com/q/455229/95441
I ran into the same problem. And while trying to find a workaround I found out that fillbetween itself isn't the problem. It has something to do with the layer settings. Adding these snippets to any picture using \spy breaks the whole thing like in your example:
As fillbetween uses similar code, this is probably the reason that fillbetween clashes with spy.
Just as a side-note: axis on top works fine.
There was added an answer to the question that states that behavior is not a bug in PGFPlots but a core PGF bug.