# pgfplots - Provide a detailed plot inside the main plot

I have a main plot and inside it I would like to add a smaller plot that offers a higher level of detail.

A rough illustration of the above is:

Notice that the smaller plot provides a more detailed evolution of the blue curve when the latter approaces the x-axis.

How can I do that using the pgfplots package?

-
Is zooming in a valid option? If so you can try the spy library of TikZ. – percusse Mar 2 '13 at 15:12

I'm not sure why the spy library isn't suitable, but you can achieve what you want by using

\newsavebox{\mybox}
\savebox{\mybox}{%
<code for miniature figure>
}


and then \usebox{\mybox} at an appropriate place on the axis. Note that you can't use a node directly as pgfplots won't allow you to nest axis.

% arara: pdflatex
\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}

\newsavebox{\mybox}
\savebox{\mybox}{%
\begin{tikzpicture}
\begin{axis}[xmin=0,xmax=25,
ymin=0,ymax=1,
grid=both,
width=6cm,
height=3cm]
\end{axis}
\end{tikzpicture}
}

\begin{tikzpicture}
\begin{axis}[xmin=0,xmax=25,
ymin=0,ymax=1,
grid=both]

gee thanks @cmhughes!! As per the spy library, I got the idea (obviously wrong) from the examples and www.texample.com that the miniature would be located outside the main plot. – niels Mar 2 '13 at 21:02
you can add the axis property axis background/.style={fill=white} so that the grid lines of the two plots do not mix. – niels Mar 2 '13 at 21:28