I'd like to place an inset axis inside a parent axis with pgplots
. The position, width and height of the inset axis should be specified using the data coordinates of the parent axis. This is what I got so far:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=\textwidth,name=mainplot]
\addplot {x};
\coordinate (insetSW) at (axis cs:-4,2); % south west corner of inset
\coordinate (insetNE) at (axis cs:-2,4); % north east corner of inset
\end{axis}
\begin{axis}[at={(insetSW)},anchor=south west,name=inset]
\addplot {x};
\end{axis}
\end{tikzpicture}
\end{document}
The south west corner of the inset is at the correct position. How can I calculate the width and height of the inset, so that its north east corner is at insetNE
?
Or, is it possible to specify the axis dimensions by providing two coordinates to \begin{axis}[..]
?
\spy
. The questions you referenced look very interesting, however, as far as I can see, they don't address the problem of specifying width and height of the inset in parent axis coordinates.