【问题标题】:Plotting only the common data in a data series with GNUPlot使用 GNUPlot 仅绘制数据系列中的公共数据
【发布时间】:2013-08-01 08:59:06
【问题描述】:

我正在尝试创建一个图表,其中显示来自两个不同数据源的两条线——它们是时间序列。我的问题是一个来源每天都有数据,而另一个来源有零星数据(并且稍后开始)。如下图:

我使用以下代码:

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 有关吗?

谢谢:)

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    您可以使用stats 命令来确定两个数据文件的xrange。这在 timedata 模式下不起作用,但由于您将时间作为时间戳记,您可以在设置为 timedata 模式之前执行此操作:

    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 空白字段分隔的文件,日期/时间在引号中的第一个字段中。我没有找到将这个文件与 gnuplot stats 命令一起使用的方法。需要设置 timefmt '"..."' 来告诉 gnuplot 第一个字段有引号。将文件重写为 csv 允许我使用 stats 命令。 '''set datafile sep whitespace''' 放回数据文件设置,以便我可以使用空格分隔文件进行绘图。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-24
    • 1970-01-01
    相关资源
    最近更新 更多