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 trying to draw lines between two different tikz-drawings, placed in subfig-environments, for example the corners of the small blue rectangle in the left image and the corners of the axis environment of the right image.

Sample

As the two figures will become very large, I need to export them with externalize. Therefore I'd also like to use the subfig library and not groupplots.

I thought it would work with the remember picture and the overlay keywords, but first attempts only brought errors, so I fear there might be a conflict with remember picture and externalize. I already found a good description how to reference corners of a rectangle.

Is it possible to draw lines as indicated in the sample picture? Is it possible in combination of externalize and subfig (if not I would prefer groupplots and externalize before subfig and no externalize, though the overlay image don't need to be 'externalized')?

Here is my minimum example:

\documentclass[parskip]{scrartcl}
\usepackage{tikz,pgfplots,subfig, lipsum}
% \usetikzlibrary{external}
% \tikzexternalize[figure list=true]
\begin{document}

\lipsum[1]
\begin{figure}[h]
    \centering
    \subfloat[Overview.]{
        \begin{tikzpicture}[trim axis left, trim axis right]
            \begin{axis}[domain=-10:10,x post scale=0.5]
                \addplot+[red,mark=none]{x^2};
                \draw[fill=blue,opacity=0.3] (axis cs:-2,-0.5) rectangle (axis cs:2,5);
            \end{axis}
        \end{tikzpicture}
    }\quad
    \subfloat[Detail.]{
        \begin{tikzpicture}[trim axis left, trim axis right]
            \begin{axis}[xmin=-2,xmax=2,ymin=-0.5,ymax=5,domain=-2:2,mark=none]
                \addplot+[red,mark=none]{x^2};
            \end{axis}
        \end{tikzpicture}
    }
    \caption{Curve.}
\end{figure}
\lipsum[2]

\end{document}

Thanks a lot!

share|improve this question
    
I think you are looking for this : tex.stackexchange.com/questions/42585/… –  percusse Aug 19 '12 at 11:29
    
As far as I understood they are creating one image with another image within. If there is no solution for my question I try to add a small overview in my detailed plot, but I'd rather place them side by side and compute them independently. In the end the two pictures look like this: i.imgur.com/tCoIj.png –  kromuchi Aug 19 '12 at 11:54
    
You could try to put both plots in the same tikzpicture environment. That should work with your overlays. Only your 'subfloat'-caption will not work as easy as it does now. But you could maybe use a 'hphantom'-box to get it right? –  Matz Aug 19 '12 at 12:04
    
Is it true that it's not possible to use remember picture with two externalized pictures or can it still work somehow? As a work-around your proposition @Matz could work, I'll try it later if there's no different approach. –  kromuchi Aug 19 '12 at 12:55
    
@kromuchi Externalization makes standalone .pdf images of the graphics so that you can add them as external files. What you want is to make images standalone but still draw over them which still requires yet another tikzpicture. Instead of group plots you can use two axis environments in one picture. Scope the second and shift it to the right. –  percusse Aug 19 '12 at 13:36

1 Answer 1

up vote 6 down vote accepted

For the sake of completeness I present a short version of the groupplots-approach with faked sub-captions and possible externalization. There are different approaches (see comments under question), but this seemed the easiest for me. However, for the original grafic I realized that additional lines only make everything messy...

Result

And here the code:

\documentclass[parskip]{scrartcl}
\usepackage{tikz,pgfplots,subfig, lipsum}
\usetikzlibrary{pgfplots.groupplots}
\usetikzlibrary{fit,intersections,}
\makeatletter
\tikzset{ % fitting node, see http://goo.gl/KOvpQ
  fitting node/.style={
    inner sep=0pt,
    fill=none,
    draw=none,
    reset transform,
    fit={(\pgf@pathminx,\pgf@pathminy) (\pgf@pathmaxx,\pgf@pathmaxy)}
  },
  reset transform/.code={\pgftransformreset}
}
\makeatother
% \usetikzlibrary{external}
% \tikzexternalize[figure list=true]
\begin{document}

\lipsum[1]
\begin{figure}[h]
    \centering
        \begin{tikzpicture}
            \begin{groupplot}[domain=-10:10,group style={group size=2 by 1,vertical sep=0.7cm,horizontal sep=1.05cm,xlabels at=edge bottom,ylabels at=edge left},x label style={font=\footnotesize}]
                \nextgroupplot[x post scale=0.5,xlabel={(a) Overview.},]
                    \addplot+[red,mark=none]{x^2};
                    \draw[fill=blue,opacity=0.3] (axis cs:-2,-0.5) rectangle (axis cs:2,5) node[fitting node] (rect) {};
                \nextgroupplot[xmin=-2,xmax=2,ymin=-0.5,ymax=5,domain=-2:2,mark=none,x post scale=0.9, xlabel={(b) Detail.}]
                    \addplot+[red,mark=none]{x^2};
            \end{groupplot}

            \draw[dashed] (rect.north west) -- (group c2r1.north west);
            \draw[dashed] (rect.south west) -- (group c2r1.south west);
            \path[name path=lineA] (rect.south east) -- (group c2r1.south east);
            \path[name path=lineB] (rect.north east) -- (group c2r1.north east);
            \path[name path=lineC] (group c2r1.north west) -- (group c2r1.south west);

            \draw [dashed,name intersections={of=lineA and lineC, by=pA}] (rect.south east) -- (pA);
            \draw [dashed,name intersections={of=lineB and lineC, by=pB}] (rect.north east) -- (pB);
            \draw [dashed,gray!90,opacity=0.7] (pA) -- (group c2r1.south east);
            \draw [dashed,gray!90,opacity=0.7] (pB) -- (group c2r1.north east);

        \end{tikzpicture}
\end{figure}

\lipsum[2]
\end{document}
share|improve this answer
    
plus there is a small 3D-effect... –  kromuchi Sep 1 '12 at 21:31

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.