首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用gnuplot4.6在我的图表中跟踪趋势线?

如何使用gnuplot4.6在我的图表中跟踪趋势线?
EN

Stack Overflow用户
提问于 2019-09-05 21:32:29
回答 1查看 607关注 0票数 3

我有这些数据:

代码语言:javascript
复制
2019-08-28,384
2019-08-29,394
2019-08-30,406
2019-08-31,424
2019-09-01,439
2019-09-02,454
2019-09-03,484

和gnuplot脚本:

代码语言:javascript
复制
set title "test"
set terminal png truecolor size 960,720 background rgb "#eff1f0"
set output "/home/tbenedet/Desktop/GNUPLOT\ AIX/test.png"
set grid
set style line 1 \
    linecolor rgb '#0060ad' \
    linetype 1 linewidth 2 \
    pointtype 7 pointsize 1.5
set offsets 0.5,0.5,0,0.5
set datafile separator ","
plot "df_output.txt" using 2:xtic(1) with linespoints linestyle 1

我想画一条这样的趋势线:

但是我的数学很差,我不知道如何使用gnuplot做到这一点……有人带我去看吗?

EN

回答 1

Stack Overflow用户

发布于 2019-09-05 22:32:26

假设您的数据是由一条直线描述的,您可以使用定义这样的方程并使用fit命令。

代码语言:javascript
复制
set title "test"
set terminal pngcairo size 700,600
set output "test.png"
set grid
set style line 1 \
    linecolor rgb '#0060ad' \
    linetype 1 linewidth 2 \
    pointtype 7 pointsize 1.5
set offsets 0.5,0.5,0,0.5
set datafile separator ","
set key Left left reverse

# The equation
f(x) = a*x + b
# The fit 
fit f(x) "df_output.txt" u 0:2 via a,b

set xtics rotate by 45 right

plot \
    "df_output.txt" u 2:xtic(1) w p ls -1 pt 7 title "data points",\
    f(x) w l lc "red" title "trendline"

结果

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57806677

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档