從我的開始老問題我修改了一些參數,
我還沒有理解原因,因為間諜的中心不在,$(4,3.5)$
但在該點更接近$(3.2,3)$
(這個值是我在不同編譯後給出的)。
\spy[green!70!black,size=2cm] on (3.2,3) in node [fill=white] at (8,1);
之後就是主要問題了:
是否可以使用 TikZ 庫\usetikzlibrary{spy}
,以相同方向對該圖像進行一系列不同的矩形縮放(取自 JAMES STEWART 第七版的《CALCULUS》一書),
在哪裡可以有像這樣的縮放標籤問題(用戶@Tobi 的回答非常好)?
在這裡,我添加了我的 MWE 和相關螢幕截圖。
\documentclass{article}
\usepackage{tikz,amsmath,xcolor}
\usetikzlibrary{patterns}
\usepackage{pgfplots}
\usetikzlibrary{spy}
\begin{document}
\begin{tikzpicture}[spy using outlines={circle=.5cm, magnification=3, size=.5cm, connect spies}]
\tikzset{
hatch distance/.store in=\hatchdistance,
hatch distance=10pt,
hatch thickness/.store in=\hatchthickness,
hatch thickness=2pt
}
\makeatletter
\pgfdeclarepatternformonly[\hatchdistance,\hatchthickness]{flexible hatch}
{\pgfqpoint{0pt}{0pt}}
{\pgfqpoint{\hatchdistance}{\hatchdistance}}
{\pgfpoint{\hatchdistance-1pt}{\hatchdistance-1pt}}%
{
\pgfsetcolor{\tikz@pattern@color}
\pgfsetlinewidth{\hatchthickness}
\pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
\pgfpathlineto{\pgfqpoint{\hatchdistance}{\hatchdistance}}
\pgfusepath{stroke}
}
\makeatother
\begin{axis}[
xmin=-4,xmax=4,
xlabel={},
ymin=-3,ymax=3,
axis on top,
legend style={legend cell align=right,legend plot pos=right}]
\begin{scope}
\spy[green!70!black,size=2cm] on (3.2,3) in node [fill=white] at (8,1);
\end{scope}
\addplot[color=gray,domain=-4:4,samples=100] {x^3};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您連結到的答案似乎說他們重複繪圖、縮放並剪輯它。在pfgfplots
這之中最終可能會導致效能問題(即使不是在如此簡單的圖中),因此人們可能希望使用\savebox
es 和path picture
s 來達到
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\newsavebox\Axis
\begin{document}
\savebox\Axis{
\begin{tikzpicture}[declare function={f(\x)=pow(\x-1.5,3)-\x+3.5;}]
\begin{axis}[
xmin=-1,xmax=4,xlabel={$x$},xtick=\empty,
ymin=-1,ymax=4,ylabel={$y$},ytick=\empty,
axis lines=middle]
\addplot[color=cyan,thick,domain=-4:4,samples=51,smooth] {f(x)};
\node[circle,fill,inner sep=1.5pt,cyan] at (2.2,{f(2.2)}){};
\end{axis}
\end{tikzpicture}}
\begin{tikzpicture}
\node{\usebox\Axis};
\node[draw,minimum size=0.5cm,purple] (s1) at (1,0.2){};
\node[draw,minimum size=1cm,purple,
path picture={\path (-1*2,-0.2*2) node[scale=2]{\usebox\Axis};}] (s1')
at (2,0.2){};
\node[draw,minimum size=0.5cm,purple] (s2) at (2,0.2){};
\node[draw,minimum size=1cm,purple,
path picture={\path (-1*3,-0.2*3) node[scale=3]{\usebox\Axis};}] (s2')
at (3.5,0.2){};
\foreach \X in {1,2}
{\draw[dashed,purple] (s\X.north west) -- (s\X'.north west)
(s\X.south west) -- (s\X'.south west);}
\end{tikzpicture}
\end{document}
請注意,這可以變得更加用戶友好。然而,由於我必須或多或少地完全放棄您的程式碼才能獲得一些讓人想起我認為的目標輸出的東西,所以我將其添加為版本 0.1。
嗯,看起來不是你想要的,但是想要看到你想要的東西也不是那麼容易的事情。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{calc}
\newsavebox\Axis
\begin{document}
\savebox\Axis{
\begin{tikzpicture}[declare function={f(\x)=pow(\x-1.5,3)-\x+3.5;}]
\begin{axis}[
xmin=-1,xmax=4,xlabel={$x$},xtick=\empty,
ymin=-1,ymax=4,ylabel={$y$},ytick=\empty,
axis lines=middle]
\addplot[color=cyan,thick,domain=-4:4,samples=51,smooth] {f(x)};
\path (0,0) coordinate (O) (2.2,{f(2.2)}) node[circle,fill,inner
sep=1.5pt,cyan] (a){};
\end{axis}
\end{tikzpicture}}
\begin{tikzpicture}[spy node/.style={draw=purple,minimum size=#1*0.5cm,
path picture={{\path (-#1*\myx,-#1*\myy) node[scale=#1]{\usebox\Axis};}}}]
\node[inner sep=0pt,outer sep=0pt]{\usebox\Axis};
\path let \p1=($(a.center)-(current axis.center)$) in \pgfextra{\xdef\myx{\x1}\xdef\myy{\y1}}
(\p1) coordinate (a');
\node[draw,minimum size=0.5cm,purple] (s1) at (a'){};
\node[spy node=2] (s1') at ($(a')+(1,0)$){};
\node[spy node=4] (s4') at ($(a')+(3,0)$){};
\end{tikzpicture}
\end{document}