I have a Tikz picture, and I would like to zoom a part of the plot, but only in the x- direction. I have tried the same using spy, which zooms the plot in both axes.
However, I would like to have the zoom only in the x- direction, such that the x- values are between 0 and 4, and the y-values stay the same as the original plot. Here the MWE code I used to generate this image
\documentclass{article}
\usepackage{pgfplots}
\usepackage{spy}
\begin{document}
\begin{tikzpicture}[spy using outlines={rectangle, magnification=2.0,connect spies}]
\definecolor{color0}{rgb}{0.5,0,1}
\begin{axis}[
tick align=outside,
tick pos=left,
x grid style={white!69.0196078431373!black},
xmajorgrids,
xmin=-1.13873194890019, xmax=23.913370926904,
xtick style={color=black},
y grid style={white!69.0196078431373!black},
ymajorgrids,
ymin=-0.188281565159559, ymax=0.820231422036886,
ytick style={color=black}
]
\addplot [semithick, color0]
table {%
0 -0
0.392666189275928 0.146234676241875
0.785332378551855 0.357346773147583
1.17799856782778 0.489268004894257
1.57066475710371 0.54331648349762
1.96333094637964 0.54446005821228
2.35599713565557 0.515433371067047
2.74866332493149 0.471822828054428
3.14132951420742 0.424137800931931
3.53399570348335 0.376261025667191
3.92666189275928 0.331027746200562
4.3193280820352 0.286558628082275
4.71199427131113 0.245650976896286
5.10466046058706 0.209256753325462
5.49732664986299 0.177961841225624
5.88999283913891 0.150137931108475
6.28265902841484 0.127043500542641
6.67532521769077 0.105005994439125
7.0679914069667 0.0844438523054123
7.46065759624262 0.0641868710517883
7.85332378551855 0.0455127842724323
8.24598997479448 0.0290546175092459
8.63865616407041 0.0163740608841181
9.03132235334633 0.00487521616742015
9.42398854262226 -0.00621854094788432
9.81665473189819 -0.0153924785554409
10.2093209211741 -0.0204757731407881
10.60198711045 -0.0223412904888391
10.994653299726 -0.0231655612587929
11.3873194890019 -0.0239122491329908
11.7799856782778 -0.023980425670743
12.1726518675538 -0.0230171401053667
12.5653180568297 -0.0240400228649378
12.9579842461056 -0.026451837271452
13.3506504353815 -0.0317398309707642
13.7433166246575 -0.0386448465287685
14.1359828139334 -0.0461360029876232
14.5286490032093 -0.0533639974892139
14.9213151924852 -0.0605357810854912
15.3139813817612 -0.0656379461288452
15.7066475710371 -0.0704119727015495
16.099313760313 -0.0740573108196259
16.491979949589 -0.0768312588334084
16.8846461388649 -0.0780506506562233
17.2773123281408 -0.0803856551647186
17.6699785174167 -0.0832169875502586
18.0626447066927 -0.0862331837415695
18.4553108959686 -0.0881431698799133
18.8479770852445 -0.0910823196172714
19.2406432745205 -0.0945243760943413
19.6333094637964 -0.0998468399047852
20.0259756530723 -0.105189554393291
20.4186418423482 -0.110977195203304
20.8113080316242 -0.116975866258144
21.2039742209001 -0.124253623187542
21.596640410176 -0.130234345793724
21.9893065994519 -0.136100903153419
22.3819727887279 -0.140050023794174
22.7746389780038 -0.142440065741539
};
\coordinate (spypoint) at (axis cs:1,0.6);
\coordinate (spyviewer) at (axis cs:20,0.36);
\spy[width=1.2cm,height=2.5cm] on (spypoint) in node [fill=white] at (spyviewer);
\end{axis}
\end{tikzpicture}
\end{document}
