如何使用Gnplot4.6在我的图表中跟踪趋势线? [英] How to trace a trendline in my graph with Gnuplot 4.6?

查看:27
本文介绍了如何使用Gnplot4.6在我的图表中跟踪趋势线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据:

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

和gnplot脚本:

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

我想这样画一条趋势线:

但是我的数学很差,而且我不知道如何使用GNOUPUPT来做到这一点……有人给我看吗?

推荐答案

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

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"

结果

这篇关于如何使用Gnplot4.6在我的图表中跟踪趋势线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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