如何在 tikz 节点中打印 gnuplot 拟合参数?

如何在 tikz 节点中打印 gnuplot 拟合参数?

我已经定义了用于曲线拟合和绘图的宏:

\newcommand{\logfit}[4]{\addplot[no markers, black, line width=0.15pt] gnuplot [raw gnuplot] { %command for log fit
 f(x) = b*log(x) + c;  b=0; c=0; 
 fit f(x) '#1' u 1:#4 via b,c;    
 plot [x=#2:#3] f(x);
 } ; 
}

我使用此命令作为:

\begin{tikzpicture}[scale=0.75] 
\begin{axis}
[
title={Mytitle},
xlabel={Distance},
ylabel={time},
xtick={0,100,...,400},
ytick={0.0,0.8,...,1.0},
xmin = 0, xmax = 400,
ymin = 0, ymax = 1.0,
minor x tick num=1,
minor y tick num=2,
ymajorgrids=true,
legend entries={},
legend style={draw=none, at={(1.05,0.25)}, anchor=west, align=left},
legend cell align=left,
axis lines=left,        
]
\addplot+[] table [x={time},y={distance}] {../myfile.csv};
\logfit{../myfile.csv}{0}{100}{2};
\end{axis}
\end{tikzpicture}

我想要类似的东西:

\newcommand{\logfit}[4]{\addplot[no markers, black, line width=0.15pt] gnuplot [raw gnuplot] { %log fit
 f(x) = b*log(x) + c;  b=0; c=0; 
 fit f(x) '#1' u 1:#4 via b,c;    
 ti = sprintf("\%.2fx+\%.2f", b, c);
 plot [x=#2:#3] f(x);
 }; node[pos=1.0,right] {$ti};
}

但我无法显示ti节点中的值。有人能帮我修复这个语句或建议一种替代方法吗?提前谢谢。

相关内容