2017-05-30 84 views
3

我使用gnuplot绘制从两个单独的CSV文件中的数据的交叉点(在https://drive.google.com/open?id=0B2Iv8dfU4fTUZGV6X1Bvb3c4TWs此链接找到)。gnuplot的两个曲线

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连接查询,但它似乎没有打印出任何出于上述解释相同的原因。如果蓝线不接触绿线(即,如果它低于绿线),我想采用最接近绿线的值,这样它就成为一对一的线,与实际数据集一致(或非常接近)。

+2

除非我很错误的是,Gnuplot是这项工作的错误工具。这是一个不用于数据操作或处理的程序。你想要一个通用的编程语言。 – Wrzlprmft

+0

你能否详细说明你的意思是“交错的情节”?你想保留“紫色数据”,只收获“绿色数据”之上的内容? – ewcz

+0

我的意思是粉红色线条和绿色线条相同(或接近相同),你可以从上面的图中看到它。 –

回答

5

也许人们可能会强迫Gnuplot在一个细网格上重新插入两个数据集,保存这些辅助数据,然后逐行比较它。但是,我认为将这项任务委派给外部工具确实更为实际。

这当然不是最有效的方法,但“懒惰的方法”可能是读取数据点,将每个数据集解释为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

+1

@DestaHaileselassieHagos你可以直接使用脚本并将其输出重定向到一个文件,例如'python filter.py estimated.csv actual.csv> points.csv' – ewcz

+0

我做了,并且在这里找到了带有数据点的新图: https://drive.google.com/open?id=0B2Iv8dfU4fTUZGV6X1Bvb3c4TWs。但是,过滤后的点数少于实际数据集的10%(这是基本事实)。如果蓝线没有触及绿线,那么让我们将绿线的值与实际数据集进行一一对应(或非常接近)。让我编辑我的问题,我会将您的答案标记为已接受。 –

+0

你见过我最后一个问题ewcz吗? –