![pgfplots/ymax 的问题](https://linux22.com/image/263115/pgfplots%2Fymax%20%E7%9A%84%E9%97%AE%E9%A2%98.png)
我有两个想要连接的图形;它们都是用 pgfplots 生成的(在本例中是 gnuplot)。以下内容完全符合预期:
\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:
正如已经观察到的在回答另一个问题时但是,ymax
一旦(第二个)图具有对数轴,其行为就不会按预期进行:
\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:
所以我的问题是:如果不行的话,我应该使用对数图做什么ymax
?
顺便说一句,当我摆弄这个时,我注意到如果没有选项largelimits = false,连接线最终也会离它们应该去的地方很远;我做错了什么吗?这是代码:
\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:
答案1
线的偏移是由于PGFPlots 中的错误。您可以通过设置来解决此问题\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}
对于对数轴,解决方案在您链接到的答案中给出:使用交叉坐标系符号 ( \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}