I would like to have a spy functionality that doesn't scale the linewidth and of which the scaling of each axis can be controlled separately.
The MWE is based on these questions: Using tikzlibrary spy without magnifying line width and/or mark size & Rectangular spy in pgfplots without scaling. The only thing missing is that I would like the spyviewer to be stretched vertically (being a square), while the spypoint should remain the same.
A possible solution would be something like \begin{scope}[xscale around={...}], but that doesn't exist apparently.
MWE:
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{shapes,spy,calc}
\newcommand*\subfigheight{\linewidth}
\newcommand*\subfigwidth{\linewidth}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis y line=left,
axis x line=bottom,
style=thick,
xmin=-5, xmax=5,
ymin=-5, ymax=30,
width=\subfigwidth,
height=\subfigheight,
]
\addplot[black,smooth,mark=none,domain=-5:5] {x^2};
% Spy
\newcommand*\spyfactor{2.}
\newcommand*\spypoint{axis cs:0,0}
\newcommand*\spyviewer{axis cs:0,20}
\newcommand*\spypointwidth{0.1*\subfigwidth}
\newcommand*\spypointheight{0.02*\subfigwidth}
\node[thin, rectangle, draw, minimum width=\spypointwidth, minimum height=\spypointheight, inner sep=0pt] (spypoint) at (\spypoint) {};
\node[rectangle, draw, fill=white, minimum width=\spyfactor^2*\spypointwidth, minimum height=\spyfactor^2*\spypointheight, inner sep=0pt] (spyviewer) at (\spyviewer) {};
\draw[thin] (spypoint) edge (spyviewer);
\begin{scope}
\clip ($(spyviewer.south west)+(\pgflinewidth,\pgflinewidth)$) rectangle ($(spyviewer.north east)-(\pgflinewidth,\pgflinewidth)$);
\pgfmathparse{\spyfactor^2/(\spyfactor-1)}
\begin{scope}[scale around={\spyfactor:($(\spyviewer)!\spyfactor^2/(\spyfactor^2-1)!(\spypoint)$)}]
\addplot[black,smooth,mark=none,domain=-10:10] {x^2};
\end{scope}
\end{scope}
\end{axis}
\end{tikzpicture}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
