使用GNUPlot仅绘制数据系列中的公共数据 [英] Plotting only the common data in a data series with GNUPlot
问题描述
我正在尝试创建一个图表,以显示来自两个不同数据源的两条线-这是时间序列.我的问题是,一个来源每天都有数据,而另一个则有零星的数据(以后才开始).如下图所示:
I'm trying to create a graph which shows two lines from two different data sources – which are time-series. My problem is that one source has data for every day, and the other one has sporadic data (and starts later). Like the following image:
我使用以下代码:
set autoscale xfixmax
set autoscale xfixmin
set xdata time
set timefmt "%s"
set format x "%m/%y"
set y2tics
set terminal png size 1000,500
set datafile sep ','
plot 'a.csv' using 1:2 with line lw 1.2 title 'a' axes x1y1, \
'b.csv' using 2:5 with steps lw 2 title 'b' axes x1y2
我只想绘制两个都有数据的时间段.可能与GNUPlot有关吗?
I'd like just to plot the period where they both have data. Is that possible to do with GNUPlot?
谢谢:)
推荐答案
您可以使用stats
命令来确定两个数据文件的xrange.这在timedata模式下不起作用,但是由于您已将时间指定为时间戳,因此可以在设置为timedata模式之前执行此操作:
You can use the stats
command to determine the xrange of both data files. This does not work in timedata mode, but since you have the time given as timestamp you can do this before setting to timedata mode:
set datafile sep ','
stats 'a.csv' using 1:2 prefix 'a'
stats 'b.csv' using 2:5 prefix 'b'
xmin = (a_min_x < b_min_x ? b_min_x : a_min_x)
xmax = (a_max_x < b_max_x ? a_max_x : b_max_x)
set xdata time
set timefmt "%s"
set format x "%m/%y"
set y2tics
set xrange[xmin:xmax]
set terminal png size 1000,500
plot 'a.csv' using 1:2 with line lw 1.2 title 'a' axes x1y1, \
'b.csv' using 2:5 with steps lw 2 title 'b' axes x1y2
这篇关于使用GNUPlot仅绘制数据系列中的公共数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!