每个轴具有不同缩放比例的间谍功能

每个轴具有不同缩放比例的间谍功能

我想要一个不会缩放线宽并且可以单独控制每个轴的缩放的间谍功能。

MWE 基于以下问题:使用 tikzlibrary spy 而不放大线宽和/或标记大小&pgfplots 中的矩形间谍没有缩放。唯一缺少的是,我希望 spyviewer 能够垂直拉伸(呈正方形),而 spypoint 应该保持不变。

一个可能的解决方案是类似于的\begin{scope}[xscale around={...}],但显然不存在。

梅威瑟:

\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:

平均能量损失

相关内容