【问题标题】:How to obtain point data from a fitting curve?如何从拟合曲线中获取点数据?
【发布时间】:2018-11-29 00:27:37
【问题描述】:

我通过使用 gnuplot 拟合一些现有点来绘制曲线。

代码如下:

f1(x)=a1/(x**b1)+c1
fit f1(x) "41a091_input.txt" u 1:2 via a1,b1,c1
plot f1(x) with line lt 1 lw 4 lc rgb "blue" notitle, \
    '41a091_input.txt' using 1:2:3 with yerrorbars lw 2.2 lc rgb "blue" title "∑41a(091)"

数据如下:

21.8124 1.11693 0.00545168
30.8669 1.07328 0.00485237 
44.6701 1.04708 0.00411839
53.6699 1.03787 0.00301346
75.9751 1.02555 0.00304312

我的问题是:

如何从这条曲线上的任意一点获取数据? 比如 x=50 的时候?

【问题讨论】:

    标签: gnuplot curve-fitting


    【解决方案1】:

    好吧,你有你的拟合函数f1(x) 和参数a1,b1,c1 已经被拟合了。因此,为了获得x=50 的值,只需键入print f1(50)。 或者如果你想绘制它:

    ### start code
    reset session
    
    $Data <<EOD
    21.8124 1.11693 0.00545168
    30.8669 1.07328 0.00485237 
    44.6701 1.04708 0.00411839
    53.6699 1.03787 0.00301346
    75.9751 1.02555 0.00304312
    EOD
    
    f1(x)=a1/(x**b1)+c1
    fit f1(x) $Data u 1:2 via a1,b1,c1
    print sprintf("a1: %g, b1: %g, c1: %g", a1,b1,c1)
    
    XValue = 50
    set label 1 at XValue,f1(XValue)+0.01 sprintf("f1(%g): %g",XValue,f1(XValue)) 
    set arrow 1 from XValue,graph 0 to XValue,graph 1 nohead ls 0
    
    plot f1(x) with line lt 1 lw 4 lc rgb "blue" notitle,\
     $Data using 1:2:3 with yerrorbars lw 2.2 lc rgb "blue" title "∑41a(091)",\
     [XValue:XValue] f1(XValue) w p lt 6 lc rgb "red" ps 2
    ### end of code
    

    这会导致类似:

    【讨论】:

    • 天哪,你救了我的命!这样可行!但是我仍然不了解一些细节,例如 [XValue:XValue] 用于什么?
    • 如果我想在这一点上添加一条垂直虚线呢?
    • 删除[XValue:XValue] 看看会发生什么。这将范围限制为一个数据点。垂直虚线:例如set arrow 1 from XValue, graph 0 to XValue, graph 1 nohead ls 0 也许有更好的方法来实现这两件事。
    • 可能是绘制单个点的更好方法plot '+' using (XValue):(f1(XValue)) w p lt 6 lc rgb "red" ps 2
    猜你喜欢
    • 2020-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多