【问题标题】:How to plot time series data with time data is number of seconds passed如何用时间数据绘制时间序列数据是经过的秒数
【发布时间】:2019-11-17 21:45:04
【问题描述】:

我有以下数据,我想绘制它。

#time,load
10,35965.67
15,35233.82
20,35239.05
25,37188.61
30,36622.32
35,36538.27
....
3000,36305.84

在每一行中,第一列是经过的秒数。第二列是每 5 秒的事务总数。

我想这样绘制:

  • x 轴:时间。例如 10/15/20/25 ...
  • y 轴:交易。

这是我的配置:

set datafile separator ","
set terminal png size 900,400
set title "Transaction/second graph"
set ylabel "Transactions"
set xlabel "Seconds"
set xdata time
set format x "%s"
set key left top
set grid
plot "output.txt" using 0:1 with lines lw 2 lt 3 title 'tps'

所以 Gnuplot 生成的图像是:

此图像在轴上反转。我尝试了不同的解决方案,例如plot using 1:0,但我收到了异常。此外,看起来数据不正确。我不知道 0/60/120 的值是多少……

【问题讨论】:

  • 你想要 1:2,而不是 0:1。但是您需要先将, 替换为空格。
  • @choroba 我阅读的教程也显示“1:2”。但我试过了,我收到了一个例外。这就是为什么我改为“0:1”(我的错)。我认为这是因为分隔符。但我已将分隔符设置为逗号。有什么方法可以使用逗号吗?
  • 什么异常?设置数据文件分隔符应该可以工作。
  • plot "output.txt" using 1:2 with lines lw 2 lt 3 title 'tps' line 0: x range is invalid 这是我的例外。

标签: plot time-series gnuplot


【解决方案1】:

如果您有以秒为单位的数据并且只想显示秒数,我看不出使用set xdata time 将数据更改为 timedata 的原因。除非您想将其显示为小时:分钟:秒或天。

所以简单地使用:

plot "output.txt" u 1:2 w l lw 2 lt 3 title 'tps'

如果您以reset session 开头代码并没有什么坏处。使用此范围和数字以及其他可能导致意外结果的持久设置将被重置。如果我不使用set output,输出文件将不会被关闭并且磁盘上只有 0 kB。

代码:

### simple plot
reset session
set terminal png size 900,400
set output "myOutput.png"

set datafile separator ","
set title "Transaction/second graph"
set ylabel "Transactions"
set xlabel "Seconds"
set key left top
set grid
plot "output.txt" using 1:2 with lines lw 2 lt 3 title 'tps'
set output    # close output file and swith back to default
### end of code

结果:

【讨论】:

    【解决方案2】:

    您还需要告诉 gnuplot 输入时间的格式。 set format x "%s" 只是表示数字在图表中的格式。

    要告诉 gnuplot 时间以秒为单位,请使用

    set timefmt "%s"
    

    【讨论】:

      猜你喜欢
      • 2020-04-09
      • 1970-01-01
      • 1970-01-01
      • 2013-12-25
      • 1970-01-01
      • 2014-05-12
      • 2017-03-04
      • 2011-09-30
      相关资源
      最近更新 更多