50

我有一个关于 GNUPLOT 中 x 轴的日期和时间的快速问题。我会让代码说话:

这是我的数据:

#Time   Data in Data out
"2013-07-22 15:59:00"   6286    3730
"2013-07-22 15:58:00"   10695   14589
"2013-07-22 15:57:00"   17868   26464
"2013-07-22 15:56:00"   18880   34012
"2013-07-22 15:55:00"   19206   41192
"2013-07-22 15:54:00"   20365   43218
"2013-07-22 15:53:00"   18459   39298
"2013-07-22 15:52:00"   3420    4686
"2013-07-22 15:51:00"   3256    4942

这是生成图表的代码:

gnuplot> set title "Data usage over the last 24 hours"
gnuplot> unset multiplot
gnuplot> set xdata time
gnuplot> set style data lines  
gnuplot> set term png
Terminal type set to 'png'
Options are 'nocrop font "arial,12" fontscale 1.0 size 640,480 '
gnuplot> set timefmt "%Y-%m-%d %H:%M:%S"
gnuplot> set format x "%m-%d\n%H:%M"
gnuplot> set xlabel "Time"
gnuplot> set ylabel "Traffic" 
gnuplot> set autoscale y  
gnuplot> set xrange ["2013-07-21 16:00":"2013-07-22 16:00"]
gnuplot> set output "datausage.png"
gnuplot> plot "C:\\Users\\blah\\Desktop\\plot.tmp" using 1:2 t "inbound" w lines, "C:\\Users\\blah\\Desktop\\plot.tmp" u 1:3 t "outbound" w lines
                                                                                                                                                                 ^
         all points y value undefined!

问题是x轴之间datetimex轴上的空间吗?如果不是,您认为可能是什么问题?

4

3 回答 3

45

Gnuplot 实际上并不期望时间数据用引号引起来,所以你必须告诉它:

set timefmt '"%Y-%m-%d %H:%M:%S"'

您可以像我在这里所做的那样将双引号放在单引号内,或者转义引号:

set timefmt "\"%Y-%m-%d %H:%M:%S\""

这同样适用于您的xrange规范:

set xrange ['"2013-07-21 16:00"':'"2013-07-22 16:00"']

如果您删除数据文件中的引号,那么您可以使用原来的格式,除了列号将移动 1,因为日期占用了没有引号的两列。

于 2013-07-22T16:29:15.890 回答
7

答案似乎是肯定的,问题出在空间上。

这样做似乎可以解决它:

set datafile separator ","

并且实际上用逗号分隔时间和数据。

于 2013-07-22T16:12:35.203 回答
7

据我了解,指令的顺序很重要,我可以使用:

  • 用于数据,timefmt必须与 xrange 相同
  • format x仅用于显示

            set xdata time
            set timefmt "%Y%m%dT%H%M%S"
            set format x "%Y-%m-%d\n%H:%M:%S"
            # or with bash variables: set xrange ["$l_start_dt":"$l_end_dt"]
            set xrange ["20190620T000000":"20190628T000000"]
    
于 2019-06-28T12:06:12.163 回答