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 two figures that I'd like to connect; both are generated with pgfplots (and in this example, gnuplot). The following works exactly as expected:

\documentclass{beamer}
\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\begin{document}
\begin{frame}
  \tikzstyle{every picture}+=[remember picture]
  \begin{figure}
    \centering
    \begin{tikzpicture}
      \begin{axis}[height=4cm, width=10cm, enlargelimits = false]
        \addplot gnuplot[id=1, domain=0:1] {exp(x)};
        \coordinate (upper8) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (upper6) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (lower8) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymin});
        \coordinate (lower6) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymin});
      \end{axis}
    \end{tikzpicture}
  \end{figure}
  \begin{figure}
    \centering
    \begin{tikzpicture}
      \begin{axis}[height=4cm, width=10cm, enlargelimits = false]
        \addplot gnuplot[id=2, domain=.6:.8] {exp(x)};
        \coordinate (no) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (nw) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (so) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymin});
        \coordinate (sw) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymin});
      \end{axis}
    \end{tikzpicture}
  \end{figure}
  \tikz[overlay] \draw (upper8) -- (no);
  \tikz[overlay] \draw (upper6) -- (nw);
  \tikz[overlay] \draw[dashed] (lower8) -- (so);
  \tikz[overlay] \draw[dashed] (lower6) -- (sw);
\end{frame}
\end{document}
%%% Local Variables:
%%% LaTeX-command: "latex -shell-escape"
%%% End:

LaTeX rendering

As already observed in the answer to another question, ymax does not behave as expected once the (second) plot has a logarithmic axis, though:

\documentclass{beamer}
\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\begin{document}
\begin{frame}
  \tikzstyle{every picture}+=[remember picture]
  \begin{figure}
    \centering
    \begin{tikzpicture}
      \begin{axis}[height=4cm, width=10cm, enlargelimits = false]
        \addplot gnuplot[id=3, domain=0:1] {exp(x)};
        \coordinate (upper8) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (upper6) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (lower8) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymin});
        \coordinate (lower6) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymin});
      \end{axis}
    \end{tikzpicture}
  \end{figure}
  \begin{figure}
    \centering
    \begin{tikzpicture}
      \begin{axis}[height=4cm, width=10cm, enlargelimits = false, ymode=log]
        \addplot gnuplot[id=4, domain=.6:.8] {exp(x)};
        \coordinate (no) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (nw) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (so) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymin});
        \coordinate (sw) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymin});
      \end{axis}
    \end{tikzpicture}
  \end{figure}
  \tikz[overlay] \draw (upper8) -- (no);
  \tikz[overlay] \draw (upper6) -- (nw);
  \tikz[overlay] \draw[dashed] (lower8) -- (so);
  \tikz[overlay] \draw[dashed] (lower6) -- (sw);
\end{frame}
\end{document}
%%% Local Variables:
%%% LaTeX-command: "latex -shell-escape"
%%% End:

LaTeX rendering (log case)

So my question is: What should I use with the logarithmic plot if not ymax?

As an aside, when I toyed around with this, I noticed that without the option enlargelimits=false, the connecting lines end up quite far from where they're supposed to go, too; am I doing something wrong? Here's the code:

\documentclass{beamer}
\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\begin{document}
\begin{frame}
  \tikzstyle{every picture}+=[remember picture]
  \begin{figure}
    \centering
    \begin{tikzpicture}
      \begin{axis}[height=4cm, width=10cm]
        \addplot gnuplot[id=5, domain=0:1] {exp(x)};
        \coordinate (upper8) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (upper6) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (lower8) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymin});
        \coordinate (lower6) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymin});
      \end{axis}
    \end{tikzpicture}
  \end{figure}
  \begin{figure}
    \centering
    \begin{tikzpicture}
      \begin{axis}[height=4cm, width=10cm]
        \addplot gnuplot[id=6, domain=.6:.8] {exp(x)};
        \coordinate (no) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (nw) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (so) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymin});
        \coordinate (sw) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymin});
      \end{axis}
    \end{tikzpicture}
  \end{figure}
  \tikz[overlay] \draw (upper8) -- (no);
  \tikz[overlay] \draw (upper6) -- (nw);
  \tikz[overlay] \draw[dashed] (lower8) -- (so);
  \tikz[overlay] \draw[dashed] (lower6) -- (sw);
\end{frame}
\end{document}
%%% Local Variables:
%%% LaTeX-command: "latex -shell-escape"
%%% End:

LaTeX rendering (enlargelimits=true case)

share|improve this question
    
This isn't because axis cs: doesn't work with logarithmic axes (it does). Do you have a particular reason for using separate tikzpictures instead of simply putting both the axes and the drawing commands into one? –  Jake Feb 15 '13 at 19:53
    
Indeed; I do not know what made me blame axis cs when the problem is clearly with ymax. –  anonymous Feb 15 '13 at 19:57
    
I have three figures; they are inside \only<1-2>, \only<1>, and \only<2> blocks, respectively; that is why I use separate tikzpictures. Maybe the key from tex.stackexchange.com/questions/6135/… could be used instead but I expected this to be the easier route. –  anonymous Feb 15 '13 at 19:59
add comment

1 Answer

up vote 3 down vote accepted

The offset of the lines is due to a bug in PGFPlots. You can work around it by setting \pgfplotsset{cell picture=if necessary}:

\documentclass{beamer}
\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7, cell picture=if necessary}
\begin{document}
\begin{frame}
  \tikzstyle{every picture}+=[remember picture]
  \begin{figure}
    \centering
    \begin{tikzpicture}
      \begin{axis}[height=4cm, width=10cm]
        \addplot gnuplot[id=5, domain=0:1] {exp(x)};
        \coordinate (upper8) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (upper6) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (lower8) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymin});
        \coordinate (lower6) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymin});
      \end{axis}
    \end{tikzpicture}
  \end{figure}
  \begin{figure}
    \centering
    \begin{tikzpicture}
      \begin{axis}[height=4cm, width=10cm]
        \addplot gnuplot[id=6, domain=.6:.8] {exp(x)};
        \coordinate (no) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (nw) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (so) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymin});
        \coordinate (sw) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymin});
      \end{axis}
    \end{tikzpicture}
  \end{figure}
  \tikz[overlay] \draw (upper8) -- (no);
  \tikz[overlay] \draw (upper6) -- (nw);
  \tikz[overlay] \draw[dashed] (lower8) -- (so);
  \tikz[overlay] \draw[dashed] (lower6) -- (sw);
\end{frame}
\end{document}

For the logarithmic axis, the solution is given at the answer you linked to: Use the intersection coordinate system notation (\coordinate (no) at ({axis cs:0.8,0}|-{rel axis cs:0,1});):

\documentclass{beamer}
\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7, cell picture=if necessary}
\begin{document}
\begin{frame}
  \tikzstyle{every picture}+=[remember picture]
  \begin{figure}
    \centering
    \begin{tikzpicture}
      \begin{axis}[height=4cm, width=10cm, enlargelimits = false]
        \addplot gnuplot[id=3, domain=0:1] {exp(x)};
        \coordinate (upper8) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (upper6) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymax});
        \coordinate (lower8) at (axis cs:.8,\pgfkeysvalueof{/pgfplots/ymin});
        \coordinate (lower6) at (axis cs:.6,\pgfkeysvalueof{/pgfplots/ymin});
      \end{axis}
    \end{tikzpicture}
  \end{figure}
  \begin{figure}
    \centering
    \begin{tikzpicture}
      \begin{axis}[height=4cm, width=10cm, enlargelimits = false, ymode=log]
        \addplot gnuplot[id=4, domain=.6:.8] {exp(x)};
        \coordinate (no) at ({axis cs:0.8,0}|-{rel axis cs:0,1});
        \coordinate (nw) at ({axis cs:0.6,0}|-{rel axis cs:0,1});
        \coordinate (so) at ({axis cs:0.8,0}|-{rel axis cs:0,0});
        \coordinate (sw) at ({axis cs:0.6,0}|-{rel axis cs:0,0});
      \end{axis}
    \end{tikzpicture}
  \end{figure}
  \tikz[overlay] \draw (upper8) -- (no);
  \tikz[overlay] \draw (upper6) -- (nw);
  \tikz[overlay] \draw[dashed] (lower8) -- (so);
  \tikz[overlay] \draw[dashed] (lower6) -- (sw);
\end{frame}
\end{document}
share|improve this answer
    
Thank you very much! –  anonymous Feb 15 '13 at 20:41
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.