pgfplot 错误:无法将输入 '' 解析为浮点数

pgfplot 错误:无法将输入 '' 解析为浮点数

我正尝试在图表中绘制一些点。

这个想法是,拥有 A 和 B 类劳动力的三个不同的工人可以选择从事或不从事某项职业。八种分配是这些工人可以选择从事或不从事该职业的八种不同方式。

代码如下:

\begin{tikzpicture}[scale=1,thick]
            \def\LA{1}        % Total amount of A labour
             \def\LB{1}       % Total amount of B labour

        % three workers with different amounts of A and B labour
            \def\oneA{0.3}
            \def\twoA{0.5}
            \def\threeA{\LA-\oneA-\twoA}
            \def\oneB{0.6}
            \def\twoB{0.1}
            \def\threeB{\LB-\oneB-\twoB}

        % eight allocations:
        \def\aA{0}        % no workers in the occupation
        \def\aB{0}
        \def\bA{\oneA}    % worker one in the occupation
        \def\bB{\oneB}  
        \def\cA{\twoA}    % worker two in the occupation
        \def\cB{\twoB}
        \def\dA{\threeA}  % worker three in the occupation
        \def\dB{\threeB}    
        \def\eA{\oneA + \twoA}      % workers one + two in the occupation
        \def\eB{\oneB + \twoB}
        \def\fA{\oneA + \threeA}    % workers one + three in the occupation
        \def\fB{\oneB + \threeB}    
        \def\gA{\twoA + \threeA}   % workers two+ three in the occupation
        \def\gB{\twoA + \threeA}
        \def\hA{\LA}               % all workers in the occupation
        \def\hB{\LB}



         \begin{axis}[
              restrict y to domain=0:\LB,
              %samples = 100,           
              xmin = 0, xmax = \LA,
              ymin = 0, ymax = \LB,
              xlabel = $L_1^A$,
              ylabel = $L_1^B$,
              axis y line = left,    
              axis x line = bottom,
              y axis line style = {-}, 
              x axis line style = {-}
            ]

    \addplot+[nodes near coords,only marks, point meta=explicit symbolic]
    table[meta=label] {
    x               y                   label
    {\aA}           {\aB}                   a
    {\bA}           {\bB}                   b
    {\cA}           {\cB}                   c
    {\dA}           {\dB}                   d
    {\eA}           {\eB}                   e
    {\fA}           {\fB}                   f
    {\gA}           {\gB}                   g
    {\hA}           {\hB}                   h
    };

         \end{axis}
\end{tikzpicture}

我收到以下错误信息:

! Package PGF Math Error: Could not parse input '1-0.6-0.1' as a floating point
number, sorry. The unreadable part was near '-0.6-0.1'..

如果我注释掉一些行,我会发现前三个分配有效(即 a、b 和 c 有效),但是当我尝试第四个分配(d)时,它无法处理我在 \threeA 中定义的差异 1-0.6-0.1。

我十分感激任何帮助!

谢谢!

苏菲亚

答案1

试试这个(我没有测试这个,因为我目前无法访问我的电脑并且我没有可编译的 MWE)

\begin{tikzpicture}[scale=1,thick]
            \pgfmathsetmacro\LA{1}        % Total amount of A labour
             \pgfmathsetmacro\LB{1}       % Total amount of B labour

        % three workers with different amounts of A and B labour
            \pgfmathsetmacro\oneA{0.3}
            \pgfmathsetmacro\twoA{0.5}
            \pgfmathsetmacro\threeA{\LA-\oneA-\twoA}
            \pgfmathsetmacro\oneB{0.6}
            \pgfmathsetmacro\twoB{0.1}
            \pgfmathsetmacro\threeB{\LB-\oneB-\twoB}

        % eight allocations:
        \pgfmathsetmacro\aA{0}        % no workers in the occupation
        \pgfmathsetmacro\aB{0}
        \pgfmathsetmacro\bA{\oneA}    % worker one in the occupation
        \pgfmathsetmacro\bB{\oneB}  
        \pgfmathsetmacro\cA{\twoA}    % worker two in the occupation
        \pgfmathsetmacro\cB{\twoB}
        \pgfmathsetmacro\dA{\threeA}  % worker three in the occupation
        \pgfmathsetmacro\dB{\threeB}    
        \pgfmathsetmacro\eA{\oneA + \twoA}      % workers one + two in the occupation
        \pgfmathsetmacro\eB{\oneB + \twoB}
        \pgfmathsetmacro\fA{\oneA + \threeA}    % workers one + three in the occupation
        \pgfmathsetmacro\fB{\oneB + \threeB}    
        \pgfmathsetmacro\gA{\twoA + \threeA}   % workers two+ three in the occupation
        \pgfmathsetmacro\gB{\twoA + \threeA}
        \pgfmathsetmacro\hA{\LA}               % all workers in the occupation
        \pgfmathsetmacro\hB{\LB}



         \begin{axis}[
              restrict y to domain=0:\LB,
              %samples = 100,           
              xmin = 0, xmax = \LA,
              ymin = 0, ymax = \LB,
              xlabel = $L_1^A$,
              ylabel = $L_1^B$,
              axis y line = left,    
              axis x line = bottom,
              y axis line style = {-}, 
              x axis line style = {-}
            ]

    \addplot+[nodes near coords,only marks, point meta=explicit symbolic]
    table[meta=label] {
    x               y                   label
    {\aA}           {\aB}                   a
    {\bA}           {\bB}                   b
    {\cA}           {\cB}                   c
    {\dA}           {\dB}                   d
    {\eA}           {\eB}                   e
    {\fA}           {\fB}                   f
    {\gA}           {\gB}                   g
    {\hA}           {\hB}                   h
    };

         \end{axis}
\end{tikzpicture}

您不能简单地使用 进行数学运算\def。在上面的代码中,我使用了 中的计算命令pgfmath

相关内容