仿照stackexchange上的一个例子拟合对数曲线,请大佬看看哪里不对。

发布于 2021-04-07 15:50:30

试图仿照stackexchange上的一个例子拟合对数曲线,希望得到下图这样的结果:
image.png

我目前得到的结果:
image.png

这是我的代码:

\documentclass{standalone}
\usepackage{pgfplots}

\pgfplotsset{compat=1.17}


\begin{filecontents}{data.dat}
X Y
1    1535.78
2    1535.82
3    1535.86
4    1535.9
5    1535.94
6    1535.96
7    1535.98
8    1536
\end{filecontents}

\begin{document}
    \begin{tikzpicture}
    \begin{axis}[]
    \addplot [only marks, mark = *] table {data.dat};
    \addplot [no markers, red] gnuplot [raw gnuplot] { % "raw gnuplot" allows us to use arbitrary gnuplot commands
            f(x) = a*ln(x)+b;  % Define the function to fit
            %a=1;          % Set reasonable starting values here
            % Select the x-range, the file, the columns (indexing starts at 1) and the variables for fitting
            fit [0:4] f(x) 'data.dat' u 1:2 via a,b; 
            plot [x=0:8] f(x); % Specify the range to plot
    };
    \end{axis}
    \end{tikzpicture}
\end{document}

查看更多

关注者
0
被浏览
1.2k
寄存器
寄存器 2021-04-07
这家伙很懒,什么也没写!

应该是没有ln(x)这个函数,改成log(x)是可以的,在gnuplot的函数表里可以查到:log(x)就是lnlog10(x)表示以10为底的对数。

image.png

1 个回答

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览