# inset plot with pgfplots

I am using pgfplots to plot some data I have, and I wanted to generate a large plot with another plot inside of it, showing a zoom on a region of the large plot. I have noticed that when you do

\begin{tikzpicture}
\begin{axis}[width=0.45\textwidth]
%small plot
\end{axis}
\begin{axis}[width=\textwidth]
%large plot
\end{axis}
\end{tikzpicture}


the second plot starts at the same position than the first one. Is there a way to move the origin of the small plot to an empty region of the big one? Or maybe you know a better alternative...

thanks

-

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}

-
gret, thank you! –  yannick May 20 '11 at 22:04
One more question to this (I hope someone will still read this after one year): If I have not decided on the final size of the plot yet, it would be convenient to position and size the small plot relative to the large one. Is that somehow possible? –  Janek Oct 4 '12 at 15:00
@Janek sure it's possible. You can give a name to the main plot and then use this name to place the auxiliary one; for example, \documentclass{article} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[width=\textwidth,name=mainplot] \addplot {x}; \end{axis} \begin{axis}[at={(mainplot.south east)},anchor=south east,yshift=1cm,width=0.45\textwidth] \addplot {x}; \end{axis} \end{tikzpicture} \end{document}. –  Gonzalo Medina Oct 5 '12 at 2:05
Thanks Gonzalo, that works perfectly! –  Janek Oct 5 '12 at 11:03

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]