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}
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.
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}



\clipis valid for future stroking. If you move your two clip lines before the\addplotyou'll see the effect (PS usecircle [radius=0.5cm], the other form is deprecated and triggers a bug in oldpgfplots). – Rmano Mar 10 '21 at 15:16\clipand\coordinateinto a\scopeenvironment, since I defined the coordinates of the circle in axis coordiantes? – Excelsior Mar 10 '21 at 15:36tikzmarks. 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\clipcomand only works outside this environment – Excelsior Mar 10 '21 at 16:11\clipbefore addplot but into the axis works, but well, the axes are plotted. What I meant before was --- why don't you usespyand 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