0

I have a problem with the \clip command. I want to do something like \spy but add some labels etc. only to the magnified picture. Since this is not straightforward, I want to clip a zoomed graph with a circle, but this is not working for me.

Here is the MWE and the graph I could get till now:

\documentclass[border=5pt,tikz]{standalone}

\usepackage{pgfplots}

\pgfplotsset{compat=newest}

\usetikzlibrary{calc} \usetikzlibrary{intersections}

\begin{document}

\def\height{10cm}
\def\width{10cm}
\def\sc{0.8}

\def\xmin{2}
\def\xmax{5}
\def\ymin{0}
\def\ymax{20}   
\def\enlarge{0.05}

\xdef\Gda{12244}
\xdef\aa{1.87}
\xdef\reqa{2.67}
\def\f{0.001}       % scaling factor for values

\begin{tikzpicture}

    \begin{axis}[
        name=plot1,
        height=\height, 
        width=\width, 
        scale only axis=true, 
        scale=\sc, 
        enlargelimits=\enlarge, 
        xmin=\xmin,
        xmax=\xmax,
        ymin=\ymin,
        ymax=\ymax,
        restrict x to domain=\xmin:\xmax,
        restrict y to domain=\ymin:\ymax,
        samples=1000,
        ]

        \addplot[
        color=black,
        smooth,
        ]
        (x,{\f*(\Gda*(1-exp(-\aa*(x-\reqa)))^2)});

        \coordinate (spypoint) at (axis cs: \reqa,1);
        \clip[draw] (spypoint) circle (0.5cm);

    \end{axis}

\end{tikzpicture}

\end{document}

enter image description here

For me and my understanding of \clip, only the picture inside the circle should be shown. It should be an 'easy' mistake, so hopefully someone can help me with this.

** Edit:**

I just add a simple drawing in PPT to show the result of this project, but now, the problem is, that I cannot acess the predefined center of the circle.

enter image description here

I also corrected the code and this is the result so far.

MWE2

\documentclass[border=5pt,tikz]{standalone}

\usepackage{pgfplots}

\pgfplotsset{compat=newest}

\usetikzlibrary{calc} \usetikzlibrary{intersections} \usetikzlibrary{spy}

\begin{document}

\def\height{10cm}
\def\width{10cm}
\def\sc{0.8}

\def\xmin{2}
\def\xmax{5}
\def\ymin{0}
\def\ymax{20}   
\def\enlarge{0.05}

\xdef\Gda{12244}
\xdef\aa{1.87}
\xdef\reqa{2.67}
\def\f{0.001}       % scaling factor for values

\begin{tikzpicture}

    \clip[draw] (spypoint) circle [radius=4cm]; %<- the predeined point (skypoint) cannot be read, since it is in the axis environment and axis coordinates were used. 

    \begin{axis}[
        name=plot1,
        height=\height, 
        width=\width, 
        scale only axis=true, 
        scale=\sc, 
        enlargelimits=\enlarge, 
        xmin=\xmin,
        xmax=\xmax,
        ymin=\ymin,
        ymax=\ymax,
        restrict x to domain=\xmin:\xmax,
        restrict y to domain=\ymin:\ymax,
        samples=1000,
        xlabel=$\mathrm{r}$,
        ylabel=$\mathrm{V(r)}$,
        ]

        \addplot[
        color=black,
        smooth,
        ]
        (x,{\f*(\Gda*(1-exp(-\aa*(x-\reqa)))^2)});

        \pgfplotsextra{%
            \global \coordinate (spypoint) at (axis cs:\reqa,1);
        }
    \end{axis}

% \coordinate (spypoint) at (\reqa,1); \draw[fill=blue] (spypoint) circle [radius=0.05cm]; %<- here, I labeled the 'correct' center point.

\end{tikzpicture}

\end{document}

enter image description here

Excelsior
  • 2,322
  • 1
    \clip is valid for future stroking. If you move your two clip lines before the \addplot you'll see the effect (PS use circle [radius=0.5cm], the other form is deprecated and triggers a bug in old pgfplots). – Rmano Mar 10 '21 at 15:16
  • @Rmano Thanks for the fast answer. Is there a way to put the \clip and \coordinate into a \scope environment, since I defined the coordinates of the circle in axis coordiantes? – Excelsior Mar 10 '21 at 15:36
  • I do not know... maybe using tikzmarks. But I am not sure what is the final objective, this seems to be an XY problem. Maybe you can prepare a smaller, contained example showing your problem? – Rmano Mar 10 '21 at 15:46
  • @Rmano I added a picture for more clarity. My problem is, that I defined the coordinates of my circle inside the axis environment and like you mentioned, the \clip comand only works outside this environment – Excelsior Mar 10 '21 at 16:11
  • If you move the \clip before addplot but into the axis works, but well, the axes are plotted. What I meant before was --- why don't you use spy and ask a question on how to add the labels you want, instead of reinventing it? Otherways, you should do the coordinate scaling manually, and I do not how to do it... – Rmano Mar 10 '21 at 16:17
  • @Rmano Thabks for your answer. I posted a new question here (https://tex.stackexchange.com/questions/586809/problems-with-arrows-in-magnified-window-using-spy) – Excelsior Mar 11 '21 at 12:13

0 Answers0