两个图形之间的箭头

两个图形之间的箭头

我有两个图表,我想放置一个箭头,如图所示:

在此处输入图片描述

我正在使用 pgfplots 绘制图形,实际上这是代码:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\usepackage[margin = 0.9in]{geometry}
\usepackage{graphicx}
\usepackage{float}


\begin{document}


\resizebox{0.4\textwidth}{!}{
\begin{tikzpicture}
    \begin{axis}[
        grid,
        grid style = {dashed},
        axis lines = left,
        xlabel = \(t\),
        ylabel = {\(f(t)\)},
        ]
        %Below the red parabola is defined
        \addplot [
        domain=0:pi, 
        samples=1200, 
        color=black,
        line width=1pt,
        ]
        {sin(deg(x))};
        
    \end{axis}
\end{tikzpicture}
}

\resizebox{0.4\textwidth}{!}{
\begin{tikzpicture}
    \begin{axis}[
        grid,
        grid style = {dashed},
        axis lines = left,
        xlabel = \(t\),
        ylabel = {\(g(t)\)},
        ]
        %Below the red parabola is defined
        \addplot [
        domain=0:pi, 
        samples=100, 
        color=black,
        line width=1pt,
        ]
        {sin(deg(x/2))};
    \end{axis}
\end{tikzpicture}
}

\end{document}

答案1

我会将两个图放在同一个位置tikzpicture,并使用scope第二个图的环境来全局移动它。然后,您可以使用一个简单的\draw方法在它们之间添加一个箭头。

另外,避免使用\resizebox,它通常会导致不良结果。请使用scale选项tikzpicture

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\usepackage[margin = 0.9in]{geometry}
\usepackage{graphicx}
\usepackage{float}


\begin{document}


\begin{tikzpicture}[scale=0.8]
    \begin{axis}[
        grid,
        grid style = {dashed},
        axis lines = left,
        xlabel = \(t\),
        ylabel = {\(f(t)\)},
        ]
        %Below the red parabola is defined
        \addplot [
        domain=0:pi, 
        samples=1200, 
        color=black,
        line width=1pt,
        ]
        {sin(deg(x))};
        
    \end{axis}

    \draw[ultra thick, ->, >=latex] (7.3,3)--++(1,0);

    \begin{scope}[xshift=10cm]
    \begin{axis}[
        grid,
        grid style = {dashed},
        axis lines = left,
        xlabel = \(t\),
        ylabel = {\(g(t)\)},
        ]
        %Below the red parabola is defined
        \addplot [
        domain=0:pi, 
        samples=100, 
        color=black,
        line width=1pt,
        ]
        {sin(deg(x/2))};
    \end{axis}
    \end{scope}
\end{tikzpicture}

\end{document}

结果

答案2

@Miyase 答案的一个小变化:

  • 地块被命名,
  • 箭头坐标由地块名称决定
  • 轴样式收集在共同\pgfplotsset
  • xtick7s and their label are in ˙pi单位
\documentclass{article}
\usepackage[margin = 0.9in]{geometry}
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{arrows.meta}

\begin{document}
    \begin{figure}[ht]
    \centering
\pgfplotsset{
    width=0.4\linewidth,
        axis lines = left,
        grid,
        grid style = {dashed},
        xlabel = \(t\),
        xtick = {0,pi/3,2*pi/3,pi},
        xticklabels = {0,$\pi/3$, $2\pi/3$, $\pi$},
        domain = 0:pi,
        samples = 101,
        no marks,
every axis plot post/.append style={thick,red},
        trig format plots=rad,
            }

    \begin{tikzpicture}
\begin{axis}[ylabel = {\(f(t)\)}, name=plot1]
        %Below the red parabola is defined
\addplot {sin(x)};
\end{axis}

    \begin{scope}[xshift=9cm]
\begin{axis}[ylabel = {\(g(t)\)}, name=plot2]
\addplot {sin(x/2)};
\end{axis}
    \end{scope}
    
\draw[ultra thick, -Latex, shorten <=7mm, shorten >=17mm] (plot1) -- (plot2);

\end{tikzpicture}
    \end{figure}
\end{document}

在此处输入图片描述

相关内容