问题描述
我似乎无法获得gnuplot来正确绘制我的时间数据. (我使用的是4.6的补丁程序级别3.)
I can't seem to get gnuplot to properly plot my time data. (I'm using version 4.6, patchlevel 3.)
对于MWE(正常工作...),输入文件
For an MWE (well, non-working...), the input file
reset
set xdata time
set timefmt "%H:%M:%S"
set format x "%H:%M:%S"
plot '-' using ($1):($2) with lines lw 3
15:36:12 1.0
15:43:17 3.0
16:12:02 2.0
e
产生以下输出:
显然,gnuplot将小时解释为秒,而忽略其余时间.我尝试了很多其他格式的字符串(也使用单引号/双引号),但是gnuplot似乎忽略了除第一个数字以外的所有内容.
Apparently, gnuplot interprets the hours as seconds and ignores the rest. I have tried a bunch of other format strings (also single/double quotes), but gnuplot seems to ignore everything except the first number.
我的格式有问题吗,或者是错误,还是其他原因?
Is something wrong with my format, or is this a bug, or something else?
推荐答案
使用$1
显式选择第一列的 numerical 值,该值绕过任何gnuplot自动方法,将列值解释为适当(作为您的情况下的时间值).只需使用using 1:2
:
With $1
you explicitely select the numerical value of the first column, which bypasses any gnuplot automatism to interpret the column values as appropriate (as time value in your case). Simply use using 1:2
:
reset
set xdata time
set timefmt "%H:%M:%S"
set format x "%H:%M:%S"
plot '-' using 1:2 with lines lw 3
15:36:12 1.0
15:43:17 3.0
16:12:02 2.0
e
仅当使用相应列中的实际数值进行计算时,才使用语法$1
. $1
是column(1)
的快捷方式,gnuplot也知道stringcolumn(1)
和timecolumn(1)
用于其他用途.
Use the syntax $1
only when doing calculations with the actual numerical value in the respective column. $1
is a shortcut for column(1)
, gnuplot also knows stringcolumn(1)
and timecolumn(1)
for other purposes.
这篇关于gnuplot误读时间数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!