pgf icon indicating copy to clipboard operation
pgf copied to clipboard

Spy and Fill Between not working properly

Open e-dervieux opened this issue 2 years ago • 0 comments

Brief outline of the bug

This issue happens when trying to use simultaneously the libraries spy and fillbetween. Extensive discussions and a presentation of the issue are available here, and in Benjamin Desef's answer, in particular. It is also logged into PGFPlot bug tracker, and Stefan Pinnow seem to believe that it is an issue with PGF itself and not the PGFPlot implementation.

Briefly, when trying to use simultaneously spy and fillbetween on a graph, the axes and filled area disappears (see second figure of the MWE below).

Minimal working example (MWE)

%!TEX program = lualatex
\documentclass[crop, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{spy}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{fillbetween}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[]
            \addplot [name path=lower] expression {-1 + sin(deg(x))};
            \addplot [name path=upper, dashed] expression {1 + sin(deg(x))};
            \addplot [fill = gray, opacity=.1] fill between[of=upper and lower];
        \end{axis}
    \end{tikzpicture}
    \begin{tikzpicture}[
        spy using outlines = {circle,size=2cm,magnification=3,connect spies},
        ]
        \begin{axis}[]
            \addplot [name path=lower] expression {-1 + sin(deg(x))};
            \addplot [name path=upper, dashed] expression {1 + sin(deg(x))};
            \addplot [fill = gray, opacity=.1] fill between[of=upper and lower];
            \coordinate (magnifying glass) at (rel axis cs: 0.35, 0.7);
            \coordinate (spy point) at (axis cs: 0, -1);
        \end{axis}
        \spy on (spy point) in node [fill=white] at (magnifying glass);
    \end{tikzpicture}
\end{document}

e-dervieux avatar Sep 13 '23 07:09 e-dervieux