通过间谍包沿 y 轴放大

通过间谍包沿 y 轴放大

希望你一切顺利。这是我的代码,它沿两个轴放大了图的一部分。我将使用 spy 包沿 y 轴放大图的一部分。你能帮帮我吗?

\documentclass[tikz,border=2pt,png]{standalone}
    \usepackage{pgfplots}
    %\usepackage{tikz}% no needs since pgfplots loads already it
    \pgfplotsset{compat=1.7} % Set the pgf plots to a current version
    \usetikzlibrary{spy}
    
    \begin{document}
    \tikzset{new spy style/.style={spy scope={%
     magnification=5,
     size=1.25cm, 
     connect spies,
     every spy on node/.style={
       rectangle,
       draw,
       },
     every spy in node/.style={
       draw,
       rectangle,
       }
      }
     }
    } 
    \begin{tikzpicture}[new spy style]
    \begin{axis}[%
      height=0.3\textwidth,
      width=0.96\textwidth,
      name = BG,
      unbounded coords=jump,
      scale only axis,
      xmin=-3.68158764150225, xmax=4.05456770289782,
      ymin=-1.44575077919192, ymax=1.15200357048622,
      axis lines*=left,
      axis equal image]
      \addplot [
        color=blue,
        solid,
        mark=+,
        mark options={solid},
        ]
        {sin(deg(x))};     
      \addplot [
        color=red,
        solid,
        mark=*,
        mark options={solid},
        ]
        {sin(deg(x))+0.1};     
      \addplot [
        color=green,
        solid,
        mark=x,
        mark options={solid},
        ]
        {sin(deg(x))-0.1};     
        \coordinate (spypoint) at (axis cs:0,0.0); 
        \coordinate (spyviewer) at (axis cs:1.7,-.5); 
    
    \end{axis}
    %using axis coordinates and without "spy style" defined above
    \spy[width=2cm,height=3cm] on (spypoint) in node [fill=white] at (spyviewer); 
    
    \end{tikzpicture}%
    \end{document}

答案1

magnification = <value>钥匙只是 的快捷方式lens = {scale = <value>}

你可以简单地使用

lens = {yscale = 5}

但我不确定这是你想要的结果。

代码

\documentclass[tikz,border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\usetikzlibrary{spy}
\tikzset{
  new spy style/.style={
    spy scope={%
      lens={yscale=5}, connect spies,
      every spy on node/.style={rectangle, draw},
     every spy in node/.style={rectangle, draw}}}}
\begin{document}
\begin{tikzpicture}[new spy style]
\begin{axis}[
  height=0.3\textwidth, width=0.96\textwidth,
  name = BG, unbounded coords=jump, scale only axis,
  xmin=-3.68158764150225, xmax=4.05456770289782,
  ymin=-1.44575077919192, ymax=1.15200357048622,
  axis lines*=left, axis equal image]
  \addplot [
    color=blue, solid, mark=+, mark options={solid}] {sin(deg(x))};
  \addplot [
    color=red,  solid, mark=*, mark options={solid}] {sin(deg(x))+0.1};
  \addplot [
    color=green,solid, mark=x, mark options={solid}] {sin(deg(x))-0.1};
  \coordinate (spypoint)  at (axis cs:0,  0.0);
  \coordinate (spyviewer) at (axis cs:1.7,-.4);
\end{axis}
\spy[width=1cm,height=2.5cm] on (spypoint) in node [fill=white] at (spyviewer); 
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

相关内容