I am trying to zoom part of the plot residing in the axis environment. An idea I tried to use can be found here, however, when I try to compile to code, Latex reports an error. I would appreciate it if someone could provide a hint on how to circumvent this issue?
MWE can be found below.
% arara: pdflatex
% arara: clean: {files: [MWE_ScopeAxis.aux, MWE_ScopeAxis.log]}
\documentclass[tikz,border=1mm]{standalone}
\usepackage{amsmath, tikz, pgfplots}
\usetikzlibrary{calc,spy,shapes,positioning}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[spy/.style={%
draw,red,
line width=1pt,
circle,inner sep=0pt,
},
]
\newcommand*\myplots[1][]{
\addplot[color=blue,dashed]
table[row sep=crcr]{
1.250000000054 0.218471486504557\\1.27500000012472 0.235880794037559\\1.30000000004985 0.253093675278193\\1.32499999988962 0.269996702493353\\1.34999999996296 0.28660169532495\\1.37500000003271 0.302803529131698\\1.4 0.318627316831094\\1.42500000000018 0.333967811176506\\1.44999999975398 0.348915976282584\\1.47499999999985 0.363393665978672\\1.50000000000007 0.377386190083728\\1.52499999999677 0.391065980885588\\1.54999999999987 0.404406696565785\\1.5749999999932 0.417357153126701\\1.60000000000001 0.429890180101467\\1.62500000007965 0.441495914781593\\1.64999999998047 0.453420186117445\\1.67500000000006 0.464885624062778\\1.70000000000013 0.475698022605379\\1.72499999999977 0.486001302461843\\1.75000000007258 0.49588760557761\\1.77500000001522 0.505406921339204\\1.79999999999992 0.514575948858101\\1.8249999999994 0.523580224222934\\1.84999999999966 0.532346980549898\\1.87499999998767 0.540884368439134\\1.90000000002483 0.549236128880721\\1.92499999997271 0.557390601810701\\1.94999999999657 0.565349329095157\\1.97499999999941 0.573100654346336\\1.99999999999993 0.580661122004988\\2.02499999998678 0.588035048696743\\2.0499999999709 0.595221272967935\\2.07499999999558 0.602215073143855\\2.09999999981776 0.609014392276178\\2.12500000001126 0.615634705868222\\2.14999999999957 0.622107376143054\\2.17499999994578 0.628535289209435\\2.19999999832383 0.63479954406909\\2.225 0.640975653060916\\2.24999999999955 0.647023272731091\\2.27499999999981 0.652900079435489\\2.29999999999833 0.658608487562972\\2.32499999999118 0.664162521737991\\2.34999999999773 0.669564611132752\\2.3750000000001 0.674786909878852\\2.40000000000024 0.679871708587361\\2.42499999998267 0.68481930558268\\2.44999999993369 0.689620895991369\\2.475 0.694300387671984\\2.50000000000226 0.698847019454327\\2.52499999999607 0.703231052229968\\2.54999999999282 0.707335949070966\\2.575 0.711299740037372\\2.59999999997469 0.715121564545835\\2.62500000002107 0.719030281788718\\2.64999999998823 0.722750679025289\\2.67499999999833 0.726355404984384\\2.6999999999989 0.729841563597055\\2.72500000000001 0.733213147420525\\2.75000000000046 0.736469697155365\\2.77500000011202 0.739681867953894\\2.8 0.742786117829059\\2.82500000000028 0.745831867778158\\2.84999999999055 0.748760245235199\\2.87499999999654 0.751587709302175\\2.90000000000011 0.754337713416536\\2.92500000001402 0.756957274828441\\2.94999999995396 0.759357524849041\\2.97499999999574 0.761687855897812\\3.00000000000154 0.764338301992918\\};
% \addlegendentry{po:pid};
\addplot [color=green!50!black,dashed]
table[row sep=crcr]{
1.250000000054 0.590067068740046\\1.27500000012472 0.587559925194454\\1.30000000004985 0.586376714983635\\1.32499999988962 0.586069496190726\\1.34999999996296 0.586583764906821\\1.37500000003271 0.587586732327579\\1.4 0.589106686232638\\1.42500000000018 0.590799582313491\\1.44999999975398 0.592894933769734\\1.47499999999985 0.595115212158793\\1.50000000000007 0.597338496940835\\1.52499999999677 0.600163078036215\\1.54999999999987 0.603553183039573\\1.5749999999932 0.607355964366702\\1.60000000000001 0.611472392727962\\1.62500000007965 0.612640770551816\\1.64999999998047 0.618542970092304\\1.67500000000006 0.625478240488116\\1.70000000000013 0.63111283078678\\1.72499999999977 0.635924446858566\\1.75000000007258 0.640430875313834\\1.77500000001522 0.644633876853955\\1.79999999999992 0.647757322657836\\1.8249999999994 0.647552686193448\\1.84999999999966 0.647363620909126\\1.87499999998767 0.647117668558105\\1.90000000002483 0.646013166144435\\1.92499999997271 0.644422071010403\\1.94999999999657 0.642591297950079\\1.97499999999941 0.640866907916906\\1.99999999999993 0.639224831229371\\2.02499999998678 0.636685323281278\\2.0499999999709 0.633964341182746\\2.07499999999558 0.631446791852552\\2.09999999981776 0.628537387562625\\2.12500000001126 0.626107411465097\\2.14999999999957 0.624103000469\\2.17499999994578 0.62449136318196\\2.19999999832383 0.624449479840847\\2.225 0.6256877319412\\2.24999999999955 0.628088304645751\\2.27499999999981 0.630472877532383\\2.29999999999833 0.63283206246448\\2.32499999999118 0.635116015919806\\2.34999999999773 0.637322260692226\\2.3750000000001 0.640065236430338\\2.40000000000024 0.642534886174564\\2.42499999998267 0.644944092104574\\2.44999999993369 0.647313968075354\\2.475 0.649603381645786\\2.50000000000226 0.651905320157395\\2.52499999999607 0.654572686699921\\2.54999999999282 0.658065576936871\\2.575 0.661530686251933\\2.59999999997469 0.664985448106105\\2.62500000002107 0.667216476217143\\2.64999999998823 0.669895462979295\\2.67499999999833 0.672557424400875\\2.6999999999989 0.675234842685167\\2.72500000000001 0.677932291475736\\2.75000000000046 0.680659050710123\\2.77500000011202 0.683201448501821\\2.8 0.685708044714863\\2.82500000000028 0.688088365642656\\2.84999999999055 0.690571448381062\\2.87499999999654 0.693076214461211\\2.90000000000011 0.695575684929241\\2.92500000001402 0.698184293706798\\2.94999999995396 0.701235761040505\\2.97499999999574 0.704202908157281\\3.00000000000154 0.705980592056065\\};
}
\begin{axis}[%
width=6cm,
height=3.5cm,
unbounded coords=jump,
scale only axis,
xmin=1.25,
xmax=2,
ymin=-5,
ymax=20,
ylabel={$y$},
xlabel={$x$},
ytick = {0,5,10,15}
]
\def\spyviewersize{1.25cm}
\def\spyonclipreduce{0.5pt}
\def\spyfactorI{2}
\coordinate (spy-on 1) at (axis cs: 1.5,1);
\coordinate (spy-in 1) at (axis cs: 1.8,10);
\node[spy,minimum size={\spyviewersize/\spyfactorI}] (spy-on node 1) at (spy-on 1) {};
\node[spy,minimum size=\spyviewersize, fill = white] (spy-in node 1) at (spy-in 1) {};
\myplots
\begin{scope}
\clip (spy-in 1) circle (0.5*\spyviewersize-\spyonclipreduce);
\pgfmathsetmacro\sI{1/\spyfactorI}
\begin{scope}[shift={($\sI*(spy-in 1)-\sI*(spy-on 1)$)}]%,scale around={\spyfactorI:(spy-on 1)}]
\myplots
\end{scope}
\end{scope}
\end{axis}
\end{tikzpicture}
\end{document}
An example working perfectly fine represents a slightly modified version of the code from here and you can also find it below. Nevertheless, the axis environment is not used and neither is the plot defined through a set of points.
% arara: pdflatex
% arara: clean: {files: [MWE_circle.aux, MWE_circle.bbl, MWE_circle.bcf, MWE_circle.blg, MWE_circle.log, MWE_circle.out, MWE_circle.run.xml, MWE_circle.toc, MWE_circle.ist, MWE_circle.slo, MWE_circle.glo, MWE_circle.synctex.gz]}
\documentclass[tikz,border=1mm]{standalone}
\usetikzlibrary{calc,positioning}
\begin{document}
\begin{tikzpicture}[
% Style for the spy nodes and the connection line
spy/.style={%
draw,red,
line width=1pt,
circle,inner sep=0pt,
},
]
% Parameters
%% size of the spy-in nodes
\def\spyviewersize{1.25cm}
%% (line width of the spy nodes) / 2
%% we need this for clipping later
\def\spyonclipreduce{0.5pt}
%% first zoom
%%% factor
\def\spyfactorI{2}
%%% spy on point
\coordinate (spy-on 1) at (2.44,1);% sould be on the curve
%%% spy in point
\coordinate (spy-in 1) at (5,1);
\def\spyfactorII{2}
%%% spy on point (last spy in point)
%% the graph/picture
\def\pic{
%%% grid
%\draw [ultra thin,step=0.2,gray] (0,0) grid (6,6);
%%% graph
\draw [line width=2pt,green!70!black] (0,0) parabola [bend at start] (6,6);
\draw [line width=2pt,red!70!black] (2,0) parabola [bend={(2.5,1)}] (3,0);
%%% axes
\draw [->] (0,0) -- (6,0) node [right] {$t$};
\draw [->] (0,0) -- (0,6) node [left] {$x$};
}
% draw the original picture
\pic
% first zoom
%% spy on node
\node[spy,minimum size={\spyviewersize/\spyfactorI}] (spy-on node 1) at (spy-on 1) {};
%% spy in node
\node[spy,minimum size=\spyviewersize, fill = white] (spy-in node 1) at (spy-in 1) {};
\begin{scope}
\clip (spy-in 1) circle (0.5*\spyviewersize-\spyonclipreduce);
\pgfmathsetmacro\sI{1/\spyfactorI}
\begin{scope}[
shift={($\sI*(spy-in 1)-\sI*(spy-on 1)$)},
scale around={\spyfactorI:(spy-on 1)}
]
\pic
\end{scope}
\end{scope}
%% connect the nodes
\draw [spy] (spy-on node 1) -- (spy-in node 1);
% % print the factors
% \node [above=0pt of spy-in node 1] {$\spyfactorI\times$};
% \pgfmathsetmacro\spyfactor{\spyfactorI*\spyfactorII}
\end{tikzpicture}
\end{document}
On top of that, would it be possible to crop only the "zoomed" part of the plot and export it as a separate .pdf?
Thanks!


spylibrary, and the codes that you are linking to magnify parts of plots without magnifying the line widths. Is that what you wish to achieve? – May 08 '20 at 16:50scale aroundkey inpgfplotswithout further efforts. – May 08 '20 at 17:09\begin{scope} \clip (spyviewer.south west) rectangle (spyviewer.north east); \pgfmathparse{\spyfactor^2/(\spyfactor-1)} \begin{scope}[scale around={\spyfactor:($(\spyviewer)!\spyfactor^2/(\spyfactor^2-1)!(\spypoint)$)}] \myplots \end{scope} \end{scope}
– slm992 May 08 '20 at 17:25