在组图中连接不同图形中的点

在组图中连接不同图形中的点

我(可能很天真地)写道:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}\pgfplotsset{compat=1.13}
\usetikzlibrary{babel, calc, arrows.meta}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}[
    ]
        \begin{groupplot}[
                group style = {group size = 1 by 2},
                width=9cm, height=4cm,
                xmin=0, xmax=20, 
                ymin=0, ymax=12,
                xlabel = {x},
                ylabel = {y},
                grid,
                /tikz/declare function = {r1(\x)=2*\x/10 - \x/800*\x;
                r2(\x)=2*\x - \x/10*\x;},
            ]
            \nextgroupplot[
            ]
            \addplot[ultra thick, red,  domain=0:10] {r2(x)};
            \addplot[thick, dotted, red,  domain=10:20, forget plot] {r2(x)};
            \node (A) at (5, {r2(5)}) {A}; 
            \nextgroupplot[
            ]

            \addplot[ultra thick, cyan,  domain=0:20] {r1(x)};
            \node (B) at (5, {r1(5)}) {B}; 
            % does not work:
            \draw [gray, ultra thick, ->] (A) -- (B);
        \end{groupplot}

\end{tikzpicture}
\end{document}

并得到:

输出

我期望箭头从上方的图表指向下方的图表;显然这里需要一些偏移,但我无法找到它。

是否可以在图表中标记位置绝对地这样我就可以从另一个地块到达它?

答案1

移动

\draw [gray, ultra thick, ->] (A) -- (B);

\end{groupplot},并且运行良好。

(我不知道在较低层次上究竟发生了什么,但看起来箭头的起点与节点A也在组的第二个图中时得到的起点相同。)

工作箭头

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}\pgfplotsset{compat=1.13}
\usetikzlibrary{babel, calc, arrows.meta}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}[
    ]
        \begin{groupplot}[
                group style = {group size = 1 by 2},
                width=9cm, height=4cm,
                xmin=0, xmax=20, 
                ymin=0, ymax=12,
                xlabel = {x},
                ylabel = {y},
                grid,
                /tikz/declare function = {r1(\x)=2*\x/10 - \x/800*\x;
                r2(\x)=2*\x - \x/10*\x;},
            ]
            \nextgroupplot[
            ]
            \addplot[ultra thick, red,  domain=0:10] {r2(x)};
            \addplot[thick, dotted, red,  domain=10:20, forget plot] {r2(x)};
            \node (A) at (5, {r2(5)}) {A}; 
            \nextgroupplot[
            ]

            \addplot[ultra thick, cyan,  domain=0:20] {r1(x)};
            \node (B) at (5, {r1(5)}) {B}; 

        \end{groupplot}
        % it works down here
        \draw [gray, ultra thick, ->] (A) -- (B);
\end{tikzpicture}
\end{document}

相关内容