如何解决从原始数据中减去平滑数据
我想知道在做这种事情时是否有办法从原始数据中减去平滑数据:
plot ["17.12.2020 08:00:00":"18.12.2020 20:00:00"] 'data3-17-28.csv1' using 4:5 title 'Sensor 3' with lines,\
'' using 4:5 smooth acsplines
或者,我当然需要在外部进行。
解决方法
正如@Suntory 已经建议您可以将平滑数据绘制到表格中。
但是,请记住,数据点的数量将由 set samples
决定,默认设置为 100,平滑后的数据点将是等距的。因此,如果您 set samples
到您的数据点数量并且您的数据也是等距的,那么一切都应该没问题。
在 gnuplot 中逐行连接数据并不简单,因为 gnuplot 不打算执行此类操作。
以下 gnuplot-only 解决方案假定您的数据位于没有标题和空行的数据块 $Data
中。如果没有,您可以将它从文件 with table
绘制到名为 $Data
的表中,或者在此问题的公认答案中使用以下方法:gnuplot: load datafile 1:1 into datablock
如果没有等距数据,则需要对数据进行插值,这在gnuplot中也不是很直接,参见:Resampling data with gnuplot
这取决于您:您要么使用外部工具(可能不是平台独立的),要么应用一个有些麻烦的平台独立gnuplot-only 解决方案。
代码:
### plot difference of data to smoothed data
reset session
$Data <<EOD
1 0
2 13
3 16
4 17
5 11
6 8
7 0
EOD
stats $Data u 0 nooutput # get number of rows or datapoints
set samples STATS_records
set table $Smoothed
plot $Data u 1:2 smooth acsplines
unset table
# put both datablock into one
set print $Difference
do for [i=1:|$Data|] {
print sprintf('%s %s',$Data[i],$Smoothed[i+4])
}
set print
plot $Data u 1:2 w lp pt 7,\
$Smoothed u 1:2 w lp pt 6,\
$Difference u 1:($2-$4) w lp pt 4 lc "red"
### end of code
结果:
,如果我明白你会喜欢这个:
首先将smooth的数据写入out.csv文件
set table "out.csv" separator comma
plot 'file' u 4:5 smooth acsplines
unset table
然后这一行会将“out.csv”作为附加列粘贴到文件中。您可能需要使用 sed 命令删除第一行 (sed '1,4d' out.csv)
stats 'file' matrix
多亏了 stats,我们会自动获取原始数据中的列数 (STATS_size_x)。
plot "< paste -d' ' file out.csv" u 4:($5-$(STATS_size_x+2)) w l
你能不能在你的数据上试试这个小代码。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。