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 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:

enter image description here

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?

share|improve this question
1  
Is zooming in a valid option? If so you can try the spy library of TikZ. –  percusse Mar 2 '13 at 15:12
    
add comment

1 Answer 1

up vote 6 down vote accepted

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.

enter image description here

% 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]
               \addplot expression[domain=1:25,red,mark=none,very thick]{sin(deg(1/x))};
  \end{axis}
\end{tikzpicture}
}

\begin{tikzpicture}
  \begin{axis}[xmin=0,xmax=25,
               ymin=0,ymax=1,
               grid=both]
               \addplot expression[domain=1:25]{sin(deg(1/x))};
               \draw (axis cs: 13,.4)node{\usebox{\mybox}};
  \end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer
    
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
    
Nice solution. However, I noticed that the second plot will always be inside the main plot area, which crops the xtick/ytick labels when I place it near the edge. Is there a way to overcome this? –  joaocandre Jul 17 '13 at 16:04
    
@joaocandre I suppose you could move the ticks, or make them smaller, or just have a whole other subplot... –  cmhughes Jul 17 '13 at 17:28
    
first of all let me admit that this is very nice work. However I have a question. Although i managed to implement this correctly and looks fine within LaTeX, when i try to export the image as a pdf using the externalize command, I get 2 discrete image-pdf's rather than a single pdf. Any ideas? –  user41230 Nov 18 '13 at 10:21
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.