Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

up vote 8 down vote accepted

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}
share|improve this answer
    
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
add comment

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.

pgfplots and spy

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}
share|improve this answer
    
that's a nice alternative, not quite what I was looking for but still... –  yannick May 23 '11 at 17:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.