gpt4 book ai didi

linux - gnuplot - 两个图的交集

转载 作者:可可西里 更新时间:2023-11-01 11:48:31 33 4
gpt4 key购买 nike

我正在使用 gnuplot 绘制来自两个单独的 csv 文件(可在此链接中找到:https://drive.google.com/open?id=0B2Iv8dfU4fTUZGV6X1Bvb3c4TWs)的数据,这些文件具有不同的行数,生成了下图。

enter image description here

这些数据在 csv 文件中似乎没有共同的时间戳(第一列),但 gnuplot 似乎符合如上所示的绘图。

这是我用来生成绘图的 gnuplot 脚本。

# ###### GNU Plot

set style data lines
set terminal postscript eps enhanced color "Times" 20

set output "output.eps"

set title "Actual vs. Estimated Comparison"

set style line 99 linetype 1 linecolor rgb "#999999" lw 2
#set border 1 back ls 11
set key right top
set key box linestyle 50
set key width -2
set xrange [0:10]
set key spacing 1.2
#set nokey

set grid xtics ytics mytics
#set size 2
#set size ratio 0.4

#show timestamp
set xlabel "Time [Seconds]"
set ylabel "Segments"

set style line 1 lc rgb "#ff0000" lt 1 pi 0 pt 4 lw 4 ps 0

plot "estimated.csv" using ($1):2 with lines title "Estimated", "actual.csv" using ($1):2 with lines title "Actual";

有没有什么方法可以通过忽略绿色图上方的峰值来打印(写入文件)这些图的交集值?我也尝试过执行 sql-join 查询,但由于我上面解释的相同原因,它似乎没有打印出任何内容。

PS:如果蓝线没有触及绿线(即,如果它在绿线下方),我想取最近的绿线的值,这样它将是一对一的与实际数据集对应(或非常接近)。

最佳答案

也许可以以某种方式强制 Gnuplot 在精细网格上重新插入两个数据集,保存这些辅助数据,然后逐行比较。但是,我认为将此任务委托(delegate)给外部工具确实更加实用。

这当然不是最有效的方法,但是“懒惰的方法”可能是读取数据点,将每个数据集解释为 LineString(线段的集合,本质上等同于假设数据点之间的线性插值) 然后计算交点。在 Python 中,执行此操作的脚本可能如下所示:

#!/usr/bin/env python
import sys

import numpy as np
from shapely.geometry import LineString
#-------------------------------------------------------------------------------
def load_data(fname):
return LineString(np.genfromtxt(fname, delimiter = ','))
#-------------------------------------------------------------------------------
lines = list(map(load_data, sys.argv[1:]))

for g in lines[0].intersection(lines[1]):
if g.geom_type != 'Point':
continue
print('%f,%f' % (g.x, g.y))

然后在Gnuplot中,可以直接调用它:

set terminal pngcairo
set output 'fig.png'

set datafile separator comma
set yr [0:700]
set xr [0:10]

set xtics 0,2,10
set ytics 0,100,700

set grid

set xlabel "Time [seconds]"
set ylabel "Segments"

plot \
'estimated.csv' w l lc rgb 'dark-blue' t 'Estimated', \
'actual.csv' w l lc rgb 'green' t 'Actual', \
'<python filter.py estimated.csv actual.csv' w p lc rgb 'red' ps 0.5 pt 7 t ''

给出: enter image description here

关于linux - gnuplot - 两个图的交集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44264824/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com