# How to make a graph inset

I have a graph where I want to place another graph as an inset. I now have the following code which creates an inset graph on the bottom left corner. How can I move the inset to the upper right or left corner of the main graph? (Compiled with XeTeX, because I want the axis in Arial).

\documentclass[tikz]{standalone}
\usepackage{amsmath}

\usepackage{mathspec}
\setmainfont{Arial}
\setmathrm{Arial} %To get the units in Arial
\setmathsfont(Latin,Greek,Digits){Arial}

\usepackage{pgfplots} %for drawing of graphs
\pgfplotsset{compat=1.3}

\begin{document}

\begin{tikzpicture}
\begin{axis}[]
\addplot[blue] table[x=X, y=Y] {test.dat};
\end{axis};

\begin{axis}[tiny]
\addplot[red] table[x=X, y=Z] {test.dat};
\end{axis};
\end{tikzpicture}

\end{document}


You can name and anchor axes to place them relative to each other

\documentclass[tikz]{standalone}

\usepackage{mathspec}
\setmainfont{Arial}
\setmathrm{Arial} %To get the units in Arial
\setmathsfont(Latin,Greek,Digits){Arial}

\usepackage{pgfplots} %for drawing of graphs
\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
\begin{axis}[name=big one]
\end{axis}
\begin{axis}[tiny,anchor=north east,at={(big one.north east)}]
\end{axis}
\end{tikzpicture}

\end{document}


• @Roald My pleasure, – percusse Dec 27 '14 at 12:09
• Plotception! :) – Paulo Cereda Dec 28 '14 at 12:12
• @percusse Can you please show how to move the inset slightly left so that the inset x-axis labels don't run into the main plot borders? – warship Sep 13 '15 at 21:04
• @percusse Also, as a design idea, is it a good idea to set the axis tick marks of the inset plot to another color (e.g., red)? I ask because the tick marks start running into each other, but maybe that's okay from a design standpoint... – warship Sep 13 '15 at 21:09
• @warship You can modify things with custom shift values for example ([xshift=-2pt]big one.north east) or using the shift key and so on. For further stuff, sure anything that makes things clearer is fine for my taste (not to be overdone though :P) – percusse Sep 13 '15 at 21:36