inset plot with pgfplots
Depending on what exactly you're trying to highlight with the inset, the spy
library might be useful for you. It creates an insert with a magnified part of a TikZ picture.
In order to use the axis cs:
coordinate system for specifying which part to magnify, you have to create a coordinate
node in the axis, as axis cs:
is not available inside the \spy
command:
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{spy}
\begin{document}
\begin{tikzpicture}[spy using outlines={rectangle, magnification=3,connect spies}]
\begin{axis}[grid=major,no markers,domain=-5:5,enlargelimits=false]
\addplot {x^2};
\addplot {x^3};
\coordinate (spypoint) at (axis cs:0,0);
\coordinate (spyviewer) at (axis cs:0.5,-90);
\spy[width=6cm,height=1cm] on (spypoint) in node [fill=white] at (spyviewer);
\end{axis}
\end{tikzpicture}
\end{document}
You could use the xshift
, and yshift
keys:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xshift=.5\textwidth,yshift=2cm,width=0.45\textwidth]
%small plot
\end{axis}
\begin{axis}[width=\textwidth]
%large plot
\end{axis}
\end{tikzpicture}
\end{document}
You can place an inset relatively to the main plot by doing
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[remember picture]
\begin{axis}[width=\textwidth]
%large plot
\addplot {x^3};
\coordinate (insetPosition) at (rel axis cs:0.95,0.05);
\end{axis}
\begin{axis}[at={(insetPosition)},anchor={outer south east},footnotesize]
%small plot
\addplot {2*x};
\end{axis}
\end{tikzpicture}
\end{document}
which then gives you
This automatically shifts to make space for the subsets axis descriptions too. Occasionally one might want to place such a subset at a fixed coordinate, in which case you only need to exchange the definition of insetPosition to
\coordinate (insetPosition) at (axis cs:5:-140);
to achieve this effect.