使用Gnuplot时,如何在行标题中打印行的方程式? [英] When using Gnuplot, how can the equation of a line be printed in the line title?

查看:65
本文介绍了使用Gnuplot时,如何在行标题中打印行的方程式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Gnuplot绘制了数据以及线性回归线.当前,具有由Gnuplot计算的公式的该行的标题"仅为"f(x)".但是,我希望标题是回归线的方程式,例如"y = mx + c".

I have used Gnuplot to plot my data, along with a linear regression line. Currently, the 'title' of this line, which has its equation calculated by Gnuplot, is just "f(x)". However, I would like the title to be the equation of the regression line, e.g. "y=mx+c".

我可以通过从绘图信息输出中读取"m"和"c",然后重新绘制新标题来手动执行此操作.我希望该过程是自动化的,并且想知道是否可以做到这一点,以及如何去做.

I can do this manually by reading off 'm' and 'c' from the plotting info output, then re-plot with the new title. I would like this process to be automated, and was wondering if this can be done, and how to go about doing it.

推荐答案

带有数据文件Data.csv:

0   0.00000
1   1.00000
2   1.41421
3   1.73205
4   2.00000
5   2.23607

您可以使用以下方法进行线性拟合:

you can do a linear fitting with:

f(x) = a*x + b

fit f(x) 'Data.csv' u 1:2 via a, b

您可以在gnuplot中使用我认为的宏来设置您所识别的函数f(x)的图例中的标题,

You can use what I think is called a macro in gnuplot to set the title in the legend of you identified function f(x) with

title_f(a,b) = sprintf('f(x) = %.2fx + %.2f', a, b)

现在,要使用回归函数f(x)绘制数据,只需执行以下操作:

Now in order to plot the data with the regression function f(x) simply do:

plot "Data.csv" u 1:2 w l, f(x) t title_f(a,b)

您应该以以下情节告终:

You should end up with this plot:

这篇关于使用Gnuplot时,如何在行标题中打印行的方程式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆