pgfplots 简单 x 过滤器错误

pgfplots 简单 x 过滤器错误

为了绘制 t 作为 n 函数的图形,我试图过滤文件中 k 不同于 5 的行。这是投影仪:

% !TEX TS-program = pdflatexmk
\documentclass[aspectratio = 169]{beamer}
\setbeamertemplate{navigation symbols}{}
\usetheme{Boadilla}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{hyperref}
\usepackage{pgfplots}
\pgfplotsset{compat = newest, width = \textwidth, height = \axisdefaultheight}

\begin{document}

\begin{frame}
    \frametitle{Tree}
    \framesubtitle{ Time as a function of $n$}
    \begin{center}
        \begin{tikzpicture}
            \begin{axis}[
                unbounded coords=discard,
            ]
            
                \addplot+ [
                    x filter/.expression={
                        \thisrow{k} == 5 ? x : nan
                    },
                ] table [
                    col sep = comma, 
                    x = n,
                    y = tmed,
                ] {./data/test-tree.csv};
                
            \end{axis}
        \end{tikzpicture}
    \end{center}
\end{frame} % This is line 137 in the full document
\end{document}

这会导致以下错误,我已经能够将其隔离到过滤器本身:

./presentation.tex:137: Missing number, treated as zero.
<to be read again>
                   =
l.137 \end{frame}
                 ^^M
?

我有点困惑,因为我的过滤器几乎完全照搬了pgfplots 文档,但即使复制粘贴他们的例子也不起作用:

% Preamble: \pgfplotsset{width=7cm,compat=1.18}
\begin{tikzpicture}
\begin{axis}
    \addplot+[
        x filter/.expression={
            \thisrow{W} == 42 ? 0.2 : x
        },
    ] table {
        x y      W
        0 0      41
        0.5 0.5 42
        1 1      43
    };
\end{axis}
\end{tikzpicture}

作为参考,这里是该文件的一个示例test-tree.csv:(省略约 1900 行)

n, k, tq1, tmed, tq3
1, 1, 0, 1, 1
1, 2, 0, 1, 1
1, 3, 0, 1, 1
1, 4, 0, 1, 1
1, 5, 0, 1, 1
1, 6, 0, 1, 1
1, 7, 0, 1, 1
1, 8, 0, 0, 1
1, 9, 0, 1, 1

相关内容