Ric*_*oti 4 gnuplot datetime-format
我需要使用 gnuplot 在同一个图中绘制两个数据文件。第一个数据文件是这样的:
2015-02-10 10.1
2015-02-15 12.1
2015-02-20 16.1
2015-02-25 14.1
...
Run Code Online (Sandbox Code Playgroud)
第二个数据文件就像
2015-02-10-10:00 12.5
2015-02-10-15:00 21.4
2015-02-15-12:30 08.3
2015-02-15-22:00 09.3
2015-02-20-08:15 12.8
2015-02-20-17:32 16.7
2015-02-25-07:20 14.0
2015-02-25-21:39 14.5
..
Run Code Online (Sandbox Code Playgroud)
要解析第一个数据文件,timefmt应该设置为"%Y-%m-%d",对于第二个文件,应该设置为"%Y-%m-%d-%H:%M". 但是,由于两个数据文件应该一起绘制,我该如何timefmt正确定义?
对于 4.6 版及更早版本,您必须使用以下命令“手动”解析日期时间字符串strptime:
set xdata time
plot 'file1.dat' using (strptime('%Y.%m.%d', strcol(1))):2,\
'file2.dat' using (strptime('%Y.%m.%d-%H:%M', strcol(1))):2
Run Code Online (Sandbox Code Playgroud)
使用 gnuplot 版本 5,您可以直接为timecolumn函数提供时间格式,以便您可以使用任意数量的格式:
set xdata time
plot 'file1.dat' using (timecolumn(1, '%Y.%m.%.d')):2,\
'file2.dat' using (timecolumn(1, '%Y.%m.%d-%H:%M')):2
Run Code Online (Sandbox Code Playgroud)
在您的情况下,两种变体之间的差异很小,但是当日期时间分布在数据文件中timecolumn的多列时,后一种变体更舒适,因为会自动处理多列。
| 归档时间: |
|
| 查看次数: |
402 次 |
| 最近记录: |