如何在 gnuplot 中读取 12 小时(上午/下午)时间格式 [英] How to read 12h (AM/PM) timeformat in gnuplot

查看:32
本文介绍了如何在 gnuplot 中读取 12 小时(上午/下午)时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过使用现有的和自动生成的数据文件来生成一些漂亮的图表.不幸的是,我无法更改文件的格式.

I want to generate some nice graphs by using existing and auto generated data files. Unfortunately I cannot change the format of the files.

这些行包含一个时间戳和一个值.例如

The lines contain a timestamp and a value. e.g.

July 06, 2014 at 12:46PM 84.6

在 Gnuplot 中,我可以使用给定的格式标识符来读取时间戳.但是上午和下午的时间是不可能分开的.

In Gnuplot I can use the given format identifier to read the timestamp. But there is no possibility to separate between AM oder PM time.

set timefmt "%B %d, %Y at %H:%M"

对这个问题有什么建议吗?

Any suggestions on this problem?

推荐答案

以下 awk 脚本将格式化您的文件:

The following awk script will format your file:

awk '{time = $5; if(substr(time,6,2) == "PM" 
&& substr(time,1,2) < 12) add = 12; else add = 0; 
$5 = substr(time,1,2)+add "" substr(time,3,3); 
print $0}' data

这样

July 06, 2014 at 10:46AM 83.6
July 06, 2014 at 12:46PM 84.6
July 06, 2014 at 10:46PM 85.6

看起来像

July 06, 2014 at 10:46 83.6
July 06, 2014 at 12:46 84.6
July 06, 2014 at 22:46 85.6

在 gnuplot 中,您可以在绘制文件时动态执行此操作.你可以这样做(注意我需要转义 "):

within gnuplot you can do this dynamically when plotting your file. You can do (note I need to escape the "):

set timefmt "%B %d, %Y at %H:%M"
set xdata time
set format x "%H:%M"
plot "< awk '{time = $5; if(substr(time,6,2) == "PM" 
&& substr(time,1,2) < 12) add = 12; else add = 0; 
$5 = substr(time,1,2)+add "" substr(time,3,3); 
print $0}' data" u 1:6 w l

请注意,我假设 00:15 是上午 00:15.如果您的输出是上午 12:15,那么您需要相应地修改脚本.大致如下:

Note I am assuming that 00:15 is 00:15AM. If your output is 12:15AM then you need to modify the script accordingly. Something along these lines:

if(substr(time,6,2) == "AM" && substr(time,1,2) == 12) add = -12

这篇关于如何在 gnuplot 中读取 12 小时(上午/下午)时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆