pgf 图中趋势线

pgf 图中趋势线

我一直在尝试使用 pgf 图为我的数据拟合趋势线,但不幸的是,代码似乎无法找到正确的位置。我在手册中查找了线性回归的示例,但不幸的是,它没有帮助。我已经从 excel 中知道了直线方程,计算结果为 $y=21208x+346.68$。有人能想到我该如何解决这个问题吗?更糟糕的是,现在我下面给出的代码不正确!

    \documentclass{article}
    \usepackage{textcomp}
    \usepackage{pgfplots}
    \usepackage{pgfplotstable}
    \pgfplotsset{compat = newest}


    \begin{document}

    \begin{tikzpicture}
    \begin{axis}[
        title={BET Plot of Mesoporous Solid},
        xlabel={Relative pressure $P/P_0\times 10 ^{-3}$},
        ylabel={$\frac{P/P_0}{V(1-P/P_0)}$ [$m^{-3}$]},
        xmin=0, xmax=250,
        ymin=0, ymax=5000,
        xtick={0,50,100,150,200,250},
        ytick={0,1000,2000,3000,4000,5000},
        legend pos=north west,
        ymajorgrids=true,
        grid style=dashed,
    ]

    \addplot[
        color=black,
        mark=square,
        ]
        coordinates {
        (29.9025,905.43528)(63.7920,1716.5088)(97.6815,2471.0442)(122.6003,2977.7455)(145.5255,3470.4408)(174.4313,4060.0613)(194.3663,4448.5030)(208.3208,4708.7817) };

    \addplot[    
        \addplot table[y={create col/linear regression={y=Y}}]{
        (29.9025,905.43528)(63.7920,1716.5088)(97.6815,2471.0442)(122.6003,2977.7455)(145.5255,3470.4408)(174.4313,4060.0613)(194.3663,4448.5030)(208.3208,4708.7817) };

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

答案1

您使用\addplot table,但随后提供的是坐标流而不是表。此外,您说,但数据中y=Y没有调用的列:Y

\documentclass{article}


    \usepackage{pgfplots}
    \usepackage{pgfplotstable}
    \pgfplotsset{compat = newest}


    \begin{document}

    \begin{tikzpicture}
    \begin{axis}[    
        title={BET Plot of Mesoporous Solid},
        xlabel={Relative pressure $P/P_0\times 10 ^{-3}$},
        ylabel={$\frac{P/P_0}{V(1-P/P_0)}$ [$m^{-3}$]},
        xmin=0, xmax=250,
        ymin=0, ymax=5000,
        xtick={0,50,100,150,200,250},
        ytick={0,1000,2000,3000,4000,5000},
        legend pos=north west,
        ymajorgrids=true,
        grid style=dashed,
    ]

    \addplot[
        color=black,
        mark=square,
        ]
        coordinates {
        (29.9025,905.43528)(63.7920,1716.5088)(97.6815,2471.0442)(122.6003,2977.7455)(145.5255,3470.4408)(174.4313,4060.0613)(194.3663,4448.5030)(208.3208,4708.7817) };

        \addplot [thick, red] table[y={create col/linear regression}]{
        29.9025 905.43528
        63.7920 1716.5088
        97.6815 2471.0442
        122.6003 2977.7455
        145.5255 3470.4408
        174.4313 4060.0613
        194.3663 4448.5030
        208.3208 4708.7817
        };



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

相关内容