pgfplots 轴中未定义的控制序列 \draw

pgfplots 轴中未定义的控制序列 \draw

我正在用 pgfplots 绘制一个简单的正弦波,但是当我尝试用 \draw 添加注释时,编译失败:

! Undefined control sequence.
l.161                                   \draw
                 (axis cs:pi.0) -- (axis cs:pi,2);

该图的代码为:

\node at (0.4, -3) {
                                \begin{axis}[
                                        width=2.8cm,
                                        trig format plots=rad,
                                        axis lines = middle,
                                        axis line style={-},
                                        enlargelimits,
                                        ticks = none,
                                        clip=false
                                        ]
                                        \draw (axis cs:pi,0) -- (axis cs:pi,2);
                                        \addplot[domain=0:2*pi,samples=200,blue] {sin(x-(4*pi/4))};
                                \end{axis}
                        };

知道为什么会发生这种情况吗?我有 pfgplots 版本 1.16

编辑:

这是更大的 tikzpicture 图表的一部分:

\documentclass[aspectratio=169]{beamer}

\usepackage{tikz}
\usepackage{adjustbox}
\usetikzlibrary{patterns, positioning}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetheme{metropolis}

\begin{document}
\begin{frame}[fragile]
        \begin{center}
        \begin{adjustbox}{max width=0.9\paperwidth, max height = 0.8\paperwidth}
                \begin{tikzpicture}
                        \newcommand\xscale{2.5}
\foreach \xpos in {0,...,4} {
                                % weight
                                \node [circle, draw] (w\xpos) at (\xscale*\xpos, -2) {\small{$w_\xpos$}};

                        }

\node at (0.4, -3) {
                                \begin{axis}[
                                        width=2.8cm,
                                        trig format plots=rad,
                                        axis lines = middle,
                                        axis line style={-},
                                        enlargelimits,
                                        ticks = none,
                                        clip=false
                                        ]
                                        \draw (axis cs:pi,0) -- (axis cs:pi,2);
                                        \addplot[domain=0:2*pi,samples=200,blue] {sin(x-(4*pi/4))};
                                \end{axis}
                        };
\end{tikzpicture}
\end{document}

相关内容