【问题标题】:gnuplot plotting the difference interval of two datesgnuplot 绘制两个日期的差异间隔
【发布时间】:2020-06-12 02:14:23
【问题描述】:

我有以下数据文件,我需要为其绘制差异区间:


CREATEDDATE         LASTUPDATEDATE      HRS MINS SEC    DIFF_INTERVAL
10-JUN-20 10:21:24  10-JUN-20 10:24:39  0   3   15      +00 00:03:15.000000
10-JUN-20 10:21:24  10-JUN-20 10:22:18  0   0   54      +00 00:00:54.000000
10-JUN-20 10:21:24  10-JUN-20 10:22:03  0   0   39      +00 00:00:39.000000
10-JUN-20 10:21:24  10-JUN-20 10:24:39  0   3   15      +00 00:03:15.000000

我无法像上面那样绘制(不知道如何)数据,所以我尝试将数据文件格式化为只有 2 列:creationdate (timefmt "%d-%b/%H:%M:%S ") 并将 DIFF 间隔转换为秒,但我的图表仍然看起来很糟糕。


createiondate           diff interval in sec
10-JUN/10:10:24         48
10-JUN/10:10:24         195
10-JUN/10:10:24         195

这是我的方法的外观:


set title "Test"
set terminal png truecolor
xequiv = 100
yezuiv = 250
set output "/home/user/script/photo.png"
set autoscale
set xdata time
set timefmt "%d-%b/%H:%M:%S"
set xtics format "%M %S"
set xlabel "Creationdate"
set ylabel "Diff interval in seconds"
set ytics 50 nomirror
set style data lines
set grid
set key outside
set terminal png size 1400,650
plot "/home/user/script/spool.file" using 1:2 title "Orders" lc rgb "red" lw 2

您对如何处理它有什么建议,或者甚至可以绘制两个日期的差异间隔?

干杯!

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    我对您的问题的理解是您想要绘制时间差(以秒为单位)与创建日期。根据您的数据,我看到了等效的 3 种可能性:

    1. 计算 LASTUPDATEDATE 和 CREATEDATE 之间的差异
    2. 使用第 5,6 和 7 列计算您的秒数
    3. 将第 9 列转换为秒

    对我来说,第二种方法看起来最简单。 但是,在您的示例数据中, CREATEDATE 是相同的(我并不完全清楚您希望如何显示它。好吧,在彼此之上)。因此,为了更好地说明,我在下面的示例中使用了 LASTUPDATEDATE。

    代码:

    ### plot time interval vs. date time
    reset session
    
    $Data <<EOD
    CREATEDDATE         LASTUPDATEDATE      HRS MINS SEC    DIFF_INTERVAL
    10-JUN-20 10:21:24  10-JUN-20 10:24:39  0   3   15      +00 00:03:15.000000
    10-JUN-20 10:21:24  10-JUN-20 10:22:18  0   0   54      +00 00:00:54.000000
    10-JUN-20 10:21:24  10-JUN-20 10:22:03  0   0   39      +00 00:00:39.000000
    10-JUN-20 10:21:24  10-JUN-20 10:24:39  0   3   15      +00 00:03:15.000000
    EOD
    
    myTimeFmt = "%d-%b-%y %H:%M:%S"
    
    set format x "%d-%b-%y %H:%M:%S" time 
    set xtics rotate by 45 right
    set key top left
    set ylabel "Time difference / s"
    
    myDuration(c1,c2,c3) = column(c1)*3600 + column(c2)*60 + column(c3)
    
    plot $Data u (timecolumn(3,myTimeFmt)):(myDuration(5,6,7)) w lp pt 7 lw 2 lc rgb "red" ti "Duration"
    ### end of code
    

    结果:

    【讨论】:

    • 感谢您的建议。实际上,创建日期是相同的,因此显示它非常具有挑战性。我尝试应用您的解决方案,但出现以下错误:“幅度()中的未知类型”。
    • 嗯,没听说过这个错误。有没有说是哪一行?您是否使用上述代码作为复制和粘贴?如果没有,请显示您实际使用的代码。
    • 第 0 行:幅度()中的未知类型代码:set title "Test" set output "/home/user/script/photo.png" myTimeFmt="%d-%b-%y %H:%M:%S" set format x "%d-%b-%y %H:%M:%S" set xtics rotate by 45 #right set key top left set xlabel "Creationdate timeframe" set ylabel "Time difference / s" myDuration(c1,c2,c3)=column(c1)*3600+column(c2)*60+column(c3) plot "/home/user/script//spool.file" using (timecolumn(3,myTimeFmt)):(myDuration(5,6,7)) w lp pt 7 lw 2 lc rgb "red" title "Duration"
    • 我现在看到错误发生在以下行:'plot "/home/user/script//spool.file" using (timecolumn(3,myTimeFmt)):(myDuration( 5,6,7)) w lp pt 7 lw 2 lc rgb“红色”标题“持续时间”。这可能是我使用的 gnuplot 版本(4.2)引起的问题?谢谢!
    • 哎呀,这么旧的版本?你现在更新了吗?它现在工作了吗?如果其中一个答案解决了您的问题,请将其标记为可接受。
    【解决方案2】:

    我不清楚您想如何布置绘图,但这里有一个示例,使用您的原始数据样本并将每一行绘制为沿 x (using 0) 的单独条目。

    $DATA << EOD
    CREATEDDATE         LASTUPDATEDATE      HRS MINS SEC    DIFF_INTERVAL
    10-JUN-20 10:21:24  10-JUN-20 10:24:39  0   3   15      +00 00:03:15.000000
    10-JUN-20 10:21:24  10-JUN-20 10:22:18  0   0   54      +00 00:00:54.000000
    10-JUN-20 10:21:24  10-JUN-20 10:22:03  0   0   39      +00 00:00:39.000000
    10-JUN-20 10:21:24  10-JUN-20 10:24:39  0   3   15      +00 00:03:15.000000
    EOD
    
    time_format = "%d-%b-%y %H:%M:%S"
    
    set xtics 1 format "line %0g"
    set ytics time format "%tH:%tM:%tS"
    set ylabel "Elapsed time"
    set yrange [0:*]
    unset key
    set offset .5, .5, 30, 0
    
    plot $DATA skip 1 using 0:(timecolumn(3,time_format) - timecolumn(1,time_format)) with points
    

    如果您想使用第一列时间作为 x 坐标(样本集中的所有点都将位于相同的 x 坐标),请将 using 0 替换为 using (timecolumn(1,time_format)) 并相应地更改 xtics 格式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-29
      • 2014-02-12
      • 2015-09-14
      • 2015-06-21
      • 2020-02-06
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多