
の助けを借りて軸ラベルにも灰色の背景を追加して、pgfplots で長方形領域をズームするにはどうすればよいですか?そしてズームにコンテンツがありません Tikz スパイ望みどおりの結果を得ることができました。スタンドアロンを使用した場合、この例は次のようになります。
画像を生成するために、次の「スタンドアロン」コードを使用しました。
% Source 1: https://tex.stackexchange.com/questions/102477/
% Source 2: https://tex.stackexchange.com/questions/62953/
\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}
ご覧のとおり、軸を基準として \spy の座標を設定することができました (コードの終わり近く)。ただし、同じ方法でサイズを定義することはできませんでした。結果として、メイン ドキュメント内で使用するとグラフの外観が異なる場合があります。
これは、軸の設定で「高さ」と「幅」を使用したこと、および/または \spy コマンドで「cm」を使用したことに関係していると確信しています。
私が好む解決策は、軸の座標系を参照して軸のサイズも決定できるような方法で「\spy」を使用することです。「\spy」コマンドを「軸」内で移動しようとする試みは、これまですべて失敗しています。
この質問の背後にある動機は、実際のデータを使用した次の 2 つの画像からわかります。
スタンドアロンとしてコンパイルされた場合:
メインドキュメントでコンパイルされた場合の比較:
答え1
画像全体が拡大縮小されるので、\textwidth
これを拡大縮小ボックスにも使うと良いだろうと考えました\spy
。
\spy[width=2cm,height=3cm] on (spypoint) in node [fill=white] at (spyviewer);
と
\spy[width=0.2\textwidth,height=0.3\textwidth] on (spypoint) in node [fill=white] at (spyviewer);
必要な作業はこれだけです。ボックスが環境内に正しく配置され、サイズが設定されると、standalone
そのサイズと位置はメイン ドキュメントでも保持されます。