如何使用“pgfplots”在图内插入放大图?

如何使用“pgfplots”在图内插入放大图?

我从数值实验中获得了以下数据点。我使用tikz & pgfplots包绘制了这些数据点。现在我想从mu=7.5 to 11.5图表内部显示图的曲率变化,比如第一个图 (Eta05)。我使用spy包来做到这一点,但没有成功。

\documentclass{standalone}
\usepackage{tikz,pgfplots,filecontents}
\pgfplotsset{compat=1.11}
\usetikzlibrary{spy}
\begin{filecontents*}{data.csv}
    mu   & Eta05    & Eta1o5    & Eta2o5    & Eta5      & Eta10     & Eta15     & Eta25     
    2.5  & 158.086810 & 148.218338 & 141.185738 & 132.213683 & 123.803119 & 117.787777 & 108.482610 
    3.0  & 98.451835  & 87.054289  & 79.628072  & 72.106007  & 68. 486806 & 67.002723  & 65.169244  
    3.5  & 85.401668  & 74.166957  & 67.125917  & 60.992210  & 59.808002  & 59.948999  & 60.051464  
    4.0  & 80.752934  & 69.614034  & 62.786944  & 57.414396  & 57.387458  & 58.159165  & 58.879482  
    4.5  & 78.649980  & 67.543726  & 60.832928  & 55.909321  & 56.508328  & 57.571088  & 58.532668  
    5.0  & 77.574273  & 66.465392  & 59.817595  & 55.176014  & 56.147092  & 57.360550  & 58.427176  
    5.5  & 76.983310  & 65.852998  & 59.238120  & 54.782912  & 55.991561  & 57.289748  & 58.404536  
    6.0  & 76.644634  & 65.483328  & 58.883928  & 54.557119  & 55.926289  & 57.275203  & 58.412101  
    6.5  & 76.446290  & 65.249637  & 58.655427  & 54.420231  & 55.902972  & 57.283827  & 58.430182  
    7.5  & 76.262599  & 64.992702  & 58.393061  & 54.276059  & 55.905690  & 57.321824  & 58.471161  
    8.5  & 76.208315  & 64.869417  & 58.255500  & 54.208693  & 55.927382  & 57.360911  & 58.506102  
    9.5  & 76.204858  & 64.804256  & 58.173757  & 54.172047  & 55.949867  & 57.393085  & 58.532877  
    10.0 & 76.211650  & 64.783063  & 58.144280  & 54.159353  & 55.959829  & 57.406375  & 58.543584  
    11.5 & 76.244573  & 64.742614  & 58.080603  & 54.132025  & 55.983407  & 57.436788  & 58.567443  
    13.5 & 76.292395  & 64.713241  & 58.025281  & 54.106536  & 56.002348  & 57.461302  & 58.586027  
    15   & 76.323304  & 64.698158  & 57.994336  & 54.090627  & 56.010017  & 57.472000  & 58.593899  
    20   & 76.391403  & 64.660545  & 57.919966  & 54.046219  & 56.015134  & 57.484401  & 58.602444  
    25   & 76.424631  & 64.630563  & 57.868278  & 54.010977  & 56.008094  & 57.482538  & 58.600464  
    30   & 76.440877  & 64.605689  & 57.829598  & 53.982983  & 55.998462  & 57.476841  & 58.595800  
    40   & 76.452460  & 64.568135  & 57.776076  & 53.942674  & 55.980506  & 57.464379  & 58.585989  
    50   & 76.454123  & 64.542162  & 57.741491  & 53.915912  & 55.966629  & 57.454055  & 58.577986 
\end{filecontents*}
\pgfplotstableread[col sep=&]{data.csv}{\mytable}
\begin{document}
    \begin{tikzpicture}
    %\pgfplotsset{every axis/.append style={line width=1pt}}
    \begin{axis}[
    xmin=0, xmax=50,
    ymin=50, ymax=165,
    ]
    \addplot[color=magenta,mark=o,mark color=green] table[y = Eta05] from \mytable ;
\addplot[color=teal,mark=square,mark color=green] table[y = Eta1o5] from \mytable ; 
\addplot[color=green,mark=*,mark color=green] table[y = Eta2o5] from \mytable ; 
\addplot[color=blue,mark=star,mark color=green] table[y = Eta5] from \mytable ; 
\addplot[color=cyan,mark=otimes,mark color=green] table[y = Eta10] from \mytable ; 
\addplot[color=red,mark=triangle,mark color=green] table[y = Eta15] from \mytable ; 
\addplot[color=orange,mark=x,mark color=green] table[y = Eta25] from \mytable ;  
\coordinate (spypoint) at (8,76);
\coordinate (magnifyglass) at (8,89); 
\end{axis}
\spy [blue, size=2.5cm] on (spypoint)
in node[fill=white] at (magnifyglass);
    \end{tikzpicture}
\end{document}

这是我想要的输出。 在此处输入图片描述

答案1

您可以在轴内放置一个坐标并从外部引用它。

\begin{tikzpicture}[spy using outlines={circle, magnification=3, size=2.5cm, connect spies}]
\begin{axis}[ymax=110,no marks]
\pgfplotsinvokeforeach{05,1o5,5,10,15,25}{
\addplot+[mark=o] table[x=mu,y=Eta#1] \mytable;
}
\coordinate (a) at (axis cs:8.5,76);
\end{axis}
\spy [red] on (a)in node  at (4,4);
\end{tikzpicture}

在此处输入图片描述

相关内容