G轴在x轴上的日期/时间

Jos*_*rra 35 time date gnuplot

我有一个关于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
Run Code Online (Sandbox Code Playgroud)

这是生成图形的代码:

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!
Run Code Online (Sandbox Code Playgroud)

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

and*_*ras 34

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

set timefmt '"%Y-%m-%d %H:%M:%S"'
Run Code Online (Sandbox Code Playgroud)

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

set timefmt "\"%Y-%m-%d %H:%M:%S\""
Run Code Online (Sandbox Code Playgroud)

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

set xrange ['"2013-07-21 16:00"':'"2013-07-22 16:00"']
Run Code Online (Sandbox Code Playgroud)

如果删除数据文件中的引号,则可以使用原始格式,但列号将被移位1,因为日期占用了两列而没有引号.

  • 值得强调的是这个答案的第一行:<b>"Gnuplot实际上并不期望时间数据在引号中,所以你必须告诉它:"</ b> !! 谢谢.Gnuplot实际上似乎可以解析日期,但是从负面到正面的年份都有一个非常奇怪的范围. (2认同)

Jos*_*rra 7

似乎答案是肯定的,问题是空间.

这样做似乎解决了这个问题:

set datafile separator ","

实际上用逗号分隔时间和数据.

  • 这也有效.似乎当空格是分隔符时,引号被视为数据的一部分,因此您需要转义它们.当逗号是分隔符时,gnuplot显然忽略了引号. (2认同)

Pip*_*ipo 5

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

  • timefmt是数据,并具有成为x范围相同
  • 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"]
    
    Run Code Online (Sandbox Code Playgroud)