从插图到主图的箭头

从插图到主图的箭头

我想从插图中绘制一个指向主图的箭头。问题是这两个图中的坐标位置不同。我想要的是: 在此处输入图片描述

我得到的是:

在此处输入图片描述

任何帮助都将不胜感激。谢谢。

这是我的 MWE:

\documentclass[12pt]{article}

\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}
\begin{figure}[h!]
  \begin{center}

  \begin{tikzpicture}
  \begin{axis}[%
  height=3in,
  width=\textwidth,
  %name=mainplot,
  separate axis lines,
  every outer x axis line/.append style={black},
  every x tick label/.append style={font=\tiny},
  inner xsep=1pt,
  inner ysep=1pt,
  xmin=0,
  xmax=1,
  xtick={  0, 0.2, 0.4, 0.6, 0.8,   1},
  xlabel={\scriptsize Test},
  xmajorgrids,
  ylabel style={yshift=0.4cm}, %shifting the y line text
  every outer y axis line/.append style={black},
  every y tick label/.append style={font=\tiny},
  ymin=0,
  ymax=603,
  ytick={  0, 200, 400, 600},
  ymajorgrids,
  axis background/.style={fill=white}
  ]
  \addplot [color=blue,solid,line width=0.5pt]
    table[row sep=crcr]{%
  0     268\\
  0.3   546\\
  0.6   129\\
  0.9   43\\
  1      0\\
  };
  %\coordinate (insetPosition) at (rel axis cs:0.53,0.63);
  \coordinate (insetPosition) at (axis cs:0.65,300);
  \end{axis}

  \begin{axis}[%
  width=1.5in,
  height=1in,
  at={(insetPosition)},
  scale only axis,
  separate axis lines,
  every outer x axis line/.append style={black},
  every x tick label/.append style={font=\tiny},
  every y label/.append style={font=\tiny},
  inner xsep=1pt,
  inner ysep=1pt,
  xlabel near ticks,
  ylabel near ticks,
  xmin=1,
  xmax=10,
  xtick={1,  4,  7, 10},
  xmajorgrids,
  every outer y axis line/.append style={black},
  every y tick label/.append style={font=\tiny},
  ymin=0,
  ymax=20,
  ytick={ 0, 10, 20},
  ymajorgrids,
  axis background/.style={fill=white}
  ]
  \addplot [color=black,solid,line width=0.5pt]
    table[row sep=crcr]{%
  1 20\\
  10 0\\
  };
  \node[anchor=west] (pairs_s) at (rel axis cs:0.7,0.8) {\tiny Pairs};
  \node (pairs_d) at (rel axis cs:0.9,0.1) {};
  \draw[->,>=stealth](pairs_s) -- (pairs_d);
  \end{axis}
  \end{tikzpicture}%

  \end{center}
\end{figure}
\end{document}

答案1

在局部坐标系中定义坐标,并在周围的tikzpicture中绘制箭头。

\begin{tikzpicture}
\begin{axis}
...
\coordinate (arrowFrom) at (axis cs:....);
\end{axis}
\begin{axis}
...
\coordinate (arrowTo) at (axis cs:....);
\end{axis}
\draw[->] (arrowFrom) -- (arrowTo);
\end{tikzpicture}

在此处输入图片描述

\documentclass[12pt]{article}

\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}
  \begin{tikzpicture}
  \begin{axis}[%
  height=3in,
  width=\textwidth,
  %name=mainplot,
  separate axis lines,
  every outer x axis line/.append style={black},
  every x tick label/.append style={font=\tiny},
  inner xsep=1pt,
  inner ysep=1pt,
  xmin=0,
  xmax=1,
  xtick={  0, 0.2, 0.4, 0.6, 0.8,   1},
  xlabel={\scriptsize Test},
  xmajorgrids,
  ylabel style={yshift=0.4cm}, %shifting the y line text
  every outer y axis line/.append style={black},
  every y tick label/.append style={font=\tiny},
  ymin=0,
  ymax=603,
  ytick={  0, 200, 400, 600},
  ymajorgrids,
  axis background/.style={fill=white}
  ]
  \addplot [color=blue,solid,line width=0.5pt]
    table[row sep=crcr]{%
  0     268\\
  0.3   546\\
  0.6   129\\
  0.9   43\\
  1      0\\
  };
  \coordinate (insetPosition) at (axis cs:0.65,300);
  \coordinate (arrowTo) at (axis cs:0.7,120);
  \end{axis}

  \begin{axis}[%
  width=1.5in,
  height=1in,
  at={(insetPosition)},
  scale only axis,
  separate axis lines,
  every outer x axis line/.append style={black},
  every x tick label/.append style={font=\tiny},
  every y label/.append style={font=\tiny},
  inner xsep=1pt,
  inner ysep=1pt,
  xlabel near ticks,
  ylabel near ticks,
  xmin=1,
  xmax=10,
  xtick={1,  4,  7, 10},
  xmajorgrids,
  every outer y axis line/.append style={black},
  every y tick label/.append style={font=\tiny},
  ymin=0,
  ymax=20,
  ytick={ 0, 10, 20},
  ymajorgrids,
  axis background/.style={fill=white}
  ]
  \addplot [color=black,solid,line width=0.5pt]
    table[row sep=crcr]{%
  1 20\\
  10 0\\
  };
  \coordinate (arrowFrom) at (axis cs:8,15);
  \end{axis}
  \draw[-stealth,red](arrowFrom) node[above]{\tiny Pairs} -- (arrowTo);
  \end{tikzpicture}%
\end{document}

答案2

  • pairs_d node定义从第二个环境移到第一个axis环境;(正如@gernot所建议的,更改\node (name) at (where) {};\coordinate (name) at (where);以获得更清洁的来源。)
  • 将选项添加remember picturetikzpicture环境中;
  • 添加一个tikzpicture环境,remember picture, overlay其中包含draw从一个点到另一个点的线的选项。

当@gernot 发布他的答案时,我已经在写这个答案了,说实话,他的答案比我的干净得多。

相关内容