latex 中 plot 命令中的 endcsname 错误

latex 中 plot 命令中的 endcsname 错误

我使用以下内容将两列绘制为折线图。

       \begin{filecontents*}{data.dat}
    X,     Y      
    05\%,  78.02\%  
    15\%,  76.70\%  
    20\%,  76.30\%  
    50\%,  75.70\%  
    75\%,  70.40\%  
    90\%,  63.90\%
\end{filecontents*}
    
    \begin{figure}[h!]
    \begin{tikzpicture}
    \begin{axis}[
      legend style = { at = {(0.6,0.75)}},
%      unit markings=slash space,
      xlabel=Gender Neutral Pronoun (GNP) Density,
      ylabel=\% of correct predictions on Gold labels,
      xmin=0,xmax=100,
      ymin=60,ymax=80,
      ytick={60,70,...,80},
      xtick={5,20,...,100},
      grid,
      grid style={dotted}]
    
    \addplot [thick, color=blue,
    mark=square,] table {data.dat};
    \end{axis}
    \end{tikzpicture}
    \caption{Results highlighting the impact of varying gender neutral pronoun density in the Entailment split of the training corpus.}
    \end{figure}

然而对于这一行

 \addplot [thick, color=blue,
    mark=square,] table {data.dat};

我看到一条错误,提示缺少 \endcsname 或多余的 \endcsname 可能是什么原因?

日志显示:

Missing \endcsname inserted.

<to be read again> 
                   \%
l.241     mark=square,] table {data.dat};
                                         ^^M
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.

! Missing \endcsname inserted.
<to be read again> 
                   \%
l.241     mark=square,] table {data.dat};
                                         ^^M
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.

以下是日志的截图:

日志

答案1

我认为你需要用逗号而不是 . 来分隔列

\documentclass{article}

\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}
\begin{filecontents*}{data.dat}
    X,     Y      
    05\%,  78.02\%  
    15\%,  76.70\%  
    20\%,  76.30\%  
    50\%,  75.70\%  
    75\%,  70.40\%  
    90\%,  63.90\%
\end{filecontents*}
    
    \begin{figure}[h!]
    \begin{tikzpicture}
    \begin{axis}[
      legend style = { at = {(0.6,0.75)}},
%      unit markings=slash space,
      xlabel=Gender Neutral Pronoun (GNP) Density,
      ylabel=\% of correct predictions on Gold labels,
      xmin=0,xmax=100,
      ymin=60,ymax=80,
      ytick={60,70,...,80},
      xtick={5,20,...,100},
      grid,
      grid style={dotted}]
    
    \addplot [thin] table {data.dat};
    \end{axis}
    \end{tikzpicture}
    \caption{Results highlighting the impact of varying gender neutral pronoun density in the Entailment split of the training corpus.}
    \end{figure}
\end{document}

在此处输入图片描述

相关内容