我需要使用 gnuplot 在同一个图中绘制两个数据文件。第一个数据文件是这样的:
2015-02-10 10.1
2015-02-15 12.1
2015-02-20 16.1
2015-02-25 14.1
...
第二个数据文件就像
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
..
解析第一个数据文件,
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
使用 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
在您的情况下,两种变体之间的差异很小,但是当日期时间跨数据文件中的多列时,后一种变体要舒服得多,因为
timecolumn
自动处理多列。
关于gnuplot - 在具有不同 timefmt 的 gnuplot 中绘制两个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31008007/