gnuplot 5中的时间/日期处理 [英] Time / date handling in gnuplot 5
问题描述
我有以下数据集
0 22/01 5:40.416 07/01 5:59.149
1 29/01 5:49.765 14/01 5:59.036
2 05/02 5:45.675 21/01 5:52.160
3 12/02 5:44.241 28/01 5:55.160
4 19/02 5:49.330 04/02 5:44.065
5 26/02 5:48.044 11/02 5:34.803
,我想将第3列绘制为2的函数(也将5绘制为4的函数,但这不是问题).格式为日/月和分钟:seconds.xxx.
and I want to plot column 3 as a function of 2 (and also 5 as a function of 4 but that is not the problem). The format are day/month and minutes:seconds.xxx.
在gnuplot 4.6中,通过为x和y设置不同的时间格式来指示如何读取这两列是很简单的.一个有效的最小脚本是:
In gnuplot 4.6 it was somewhat straightforward to indicate how to read both columns by setting distinct time formats for x and y. A minimal script that worked is:
set xdata time
set timefmt x "%d/%m"
set format x "%b"
set ydata time
set timefmt y "%M:%S"
set format y "%M:%S"
plot 'data.dat' using 2:3
我最近升级到gnuplot 5,命令set timefmt x "%d/%m"
(及其等效的y
)现在出现错误.看来您再也不能放置x
或y
了,并且整个脚本只能使用一个timefmt
.
I recently upgraded to gnuplot 5 and the command set timefmt x "%d/%m"
(and its y
equivalent) now give an error. It seems that you cannot put x
or y
anymore, and you can only use a single timefmt
for the whole script.
发行说明指出
使用时间格式生成轴刻度标签现在由
set {xy}tics time
而不是set {xy}data time
.因此,先验 不需要调用set xdata time
或set timefmt x
输入或输出.这些较旧的命令仍然有效,但是 不推荐使用.
Use of time formats to generate axis tick labels is now controlled by
set {xy}tics time
rather than byset {xy}data time
. Thus prior calls toset xdata time
orset timefmt x
are unnecessary for either input or output. These older commands still work, but are deprecated.
我有两个问题.首先,尽管显示旧命令仍然有效",但在set timefmt x "%d/%m"
上还是出现错误.其次,也是最重要的一点,我无法弄清楚如何教gnuplot如何使用新命令读取我的x和y列.
I have two issues. First, despite the indication that "older commands still work", I get an error on set timefmt x "%d/%m"
. Second, and most important, I couldn't figure out how to teach gnuplot how to read my x and y columns using the new commands.
注意:我从2011年开始看到此问题,但是我感觉不太优雅,我想将文件保留为当前格式.
Note: I have seen this question from 2011 but I don't find it elegant and I want to keep the files with the present format.
推荐答案
他们对这个新版本所做的改进实际上使其更加灵活.您可以为每个特定的时间列指定一种格式,而不是指定默认的时间格式然后要求您的列适合该格式.这样,您不必保持一致,只要您指定每列的格式即可.您还可以将时间格式用于 x 或 y 轴.
The improvement they made with this new version actually makes it more flexible. Rather than specify a default time format and then require your columns to fit that format, you can specify a format for each particular time column. This way you don't have to be consistent, as long as you specify each column's format. You can also use a time format for more than an x or y axis.
您引用的发行说明中提到了您问题的解决方案,但是并不能很好地解释它.使用timecolumn(N,"timeformat")
函数,如下所示:
The solution to your question is mentioned in the release notes you quoted, but it doesn't explain it well. Use the timecolumn(N,"timeformat")
function, like the following:
set xtics time
set format x "%b"
set ytics time
set format y "%M:%S"
plot 'data.dat' using (timecolumn(2, "%d/%m")):(timecolumn(3, "%M:%S"))
set timefmt
行已被此新的两个参数timefunction()
代替,它使您可以为using
子句中的每一列指定格式.注意timecolumn()
周围的()
.这意味着您可以(如果需要)使用时间值进行一些数学运算.根据相同的 5.0发行说明:
The set timefmt
lines have been replaced by this new two-argument timefunction()
, which allows you to specify the format for each column in the using
clause. Notice the ()
around the timecolumn()
. This means that you could (if you wanted) do some math with the time value. According to the same 5.0 release notes:
时间坐标在内部存储为相对于标准unix纪元1970年1月1日的秒数. gnuplot的早期版本内部使用了不同的纪元(2000年1月1日).此更改解决了外部生成以秒为单位的时间时引入的不一致问题.可以使用命令
print strftime("%F",0)
确定特定gnuplot安装所使用的纪元约定.现在,时间已存储到至少毫秒精度.
Time coordinates are stored internally as the number of seconds relative to the standard unix epoch 1-Jan-1970. Earlier versions of gnuplot used a different epoch internally (1-Jan-2000). This change resolves inconsistencies introduced when time in seconds was generated externally. The epoch convention used by a particular gnuplot installation can be determined using the command
print strftime("%F",0)
. Time is now stored to at least millisecond precision.
注意对set xtics time
的更改. xtics的输出格式与您的示例相同,并且不同于timecolumn()
的第二个参数给出的输入格式.您似乎比以前具有更大的灵活性,但是语法已更改.
Notice the change to set xtics time
. The output format for the xtics is the same as in your example, and is different from the input format given by the second argument to timecolumn()
. You seem to have more flexibility than before, but the syntax has changed.
这篇关于gnuplot 5中的时间/日期处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!