在 pgfplots 中放置箭头

在 pgfplots 中放置箭头

我想在 pgfplots 中放置一个箭头来指示显著性。目前,我有以下代码:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{decorations.markings}
\begin{document}
    \begin{tikzpicture}[baseline=(current axis.east)]
        \begin{axis}

           \addplot [only marks,thick,mark=x,mark size=4, color=red, mark size=6pt] coordinates {(-2,0) (0,0)};
           \addplot [blue,thick,postaction={decorate}, decoration={markings, mark=at position 0.85 with {\arrow{>};}}] coordinates {(-2,0) (-1,0)};
           \addplot [blue,thick,postaction={decorate}, decoration={markings, mark=at position 0.85 with {\arrow{>};}}] coordinates {(0,0) (-1,0)};
           \addplot [blue,thick,postaction={decorate}, decoration={markings, mark=at position 0.5 with {\arrow{>};}}] coordinates {(-1,0) (-1,-4)};
           \addplot [blue,thick,postaction={decorate}, decoration={markings, mark=at position 0.5 with {\arrow{>};}}] coordinates {(-1,0) (-1,4)};
        \end{axis}
    \end{tikzpicture}
\end{document}

我希望它添加一个可以指向十字架的箭头来指示某些东西。

所需的箭头

答案1

您可以使用轴坐标系在图内绘制。

axis环境中,坐标的单位是不同的,因此它(1,1)与轴的单位相关,并不意味着(1cm,1cm)它在axis环境之外。

\documentclass[border=10pt]{standalone}
    
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{decorations.markings}
    
\begin{document}
    
    \begin{tikzpicture}[baseline=(current axis.east)]
        \begin{axis}
            \addplot [only marks,thick,mark=x,mark size=4, color=red, mark size=6pt] coordinates {(-2,0) (0,0)};
            \addplot [blue,thick,postaction={decorate}, decoration={markings, mark=at position 0.85 with {\arrow{>}}}] coordinates {(-2,0) (-1,0)};
            \addplot [blue,thick,postaction={decorate}, decoration={markings, mark=at position 0.85 with {\arrow{>}}}] coordinates {(0,0) (-1,0)};
            \addplot [blue,thick,postaction={decorate}, decoration={markings, mark=at position 0.5 with {\arrow{>}}}] coordinates {(-1,0) (-1,-4)};
            \addplot [blue,thick,postaction={decorate}, decoration={markings, mark=at position 0.5 with {\arrow{>}}}] coordinates {(-1,0) (-1,4)};

            \draw[<-, red, thick, shorten <=10pt] (-2,0) -- ++(1cm,1cm) node[above] {$K = 1$};

        \end{axis}
    \end{tikzpicture}
    
\end{document}

在此处输入图片描述

相关内容