具有更高时间精度的 gnuplot 替代方案
目前我正在使用 gnuplot 根据时间线绘制数据。然而,时间线的精度是毫秒,但 gnuplot 似乎只能处理秒。
我已经研究了几种替代方案,但实际上我只需要像 gnuplot 这样可以处理几分之一秒的东西。
主脚本使用的编程语言是 Python,虽然我研究过 matplotlib,但它似乎比 gnuplot 更加“繁重”。由于我不会总是更新图形方面的内容,因此我希望使其尽可能简单。
有什么建议吗?
更新
我将其与 gnuplot 一起使用:
set xdata time
set timefmt "%Y-%m-%d-%H:%M:%S"
但是没有 %f 来获取毫秒。例如,这有效:
2011-01-01-09:00:01
但我需要:
2011-01-01-09:00:01.123456
At present I'm using gnuplot to plot data against a time line. However the precision of the time line is in milliseconds but gnuplot only seems to be able to handle seconds.
I've looked at a couple of alternatives, but really I just need something like gnuplot that can cope with fractions of a second.
The programming language used for the main script is Python and whilst I've looked at matplotlib, it seems to be a lot more 'heavy duty' than gnuplot. As I won't always be the one updating the graphing side of things, I want to keep it as easy as possible.
Any suggestions?
Update
I'm using this with gnuplot:
set xdata time
set timefmt "%Y-%m-%d-%H:%M:%S"
However there is no %f to get milliseconds. For example, this works:
2011-01-01-09:00:01
but I need:
2011-01-01-09:00:01.123456
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据 gnuplot 4.6 手册,它在“时间/日期说明符”(gnuplot 4.6 PDF 第 114 页)下指出:
这意味着在读取诸如
2013-09-16 09:56:59.412
之类的时间戳时,将包含小数部分作为%S
说明符的一部分。这样的时间戳将被正确处理:并提供如下数据:
According to the gnuplot 4.6 manual it states, under "Time/date specifiers" (page 114 of the gnuplot 4.6 PDF):
What this means is that when reading timestamps such as
2013-09-16 09:56:59.412
the fractional portion will be included as part of the%S
specifier. Such a timestamp will be handled correctly with:and fed with data like:
您可以使用 或 设置刻度格式
(也许,我还没有尝试过,因为我现在更喜欢使用 Matplotlib< /a> 并且我的机器上没有安装 gnuplot):(
注意与
%S
格式字符串一起指定的位数)。更多详细信息可以在优秀的 不太常见的问题。
You can set the ticks format with
or (maybe, I have not tried it, as I now prefer to use Matplotlib and do not have gnuplot installed on my machines):
(note the number of digits specified along with the
%S
format string).More details can be found in the excellent not so Frequently Asked Questions.
我使用 gnuplot 来达到相同的目的,我的输入如下:
35010.59199,100,101
35010.76560,100,110
35011.05703,100,200
35011.08119,100,110
35011.08154,100,200
35011.08158,100,200
35011.08169,100,200
35011.10814,100,200
35011.16955,100,110
35011.16985,100,200
35011.17059,100,200
第一列是自午夜以来的秒数,逗号后面是纳秒部分。您可以将其保存在 csv 文件中,然后在 gnuplut 中执行以下操作:
I'm using gnuplot for the same purposes, my input looks like:
35010.59199,100,101
35010.76560,100,110
35011.05703,100,200
35011.08119,100,110
35011.08154,100,200
35011.08158,100,200
35011.08169,100,200
35011.10814,100,200
35011.16955,100,110
35011.16985,100,200
35011.17059,100,200
The first column is seconds since midnight and after the comma a nanosecond part. You can save this in a csv file and in gnuplut do:
我最初误解了你的问题。我认为时间格式的更精细分辨率是 gnuplot 的一个大问题,据我所知,这个问题尚未实现。
一种可能的解决方法是使用 awk 将日期转换为秒数
,然后只需执行常规的双倍绘图,然后忘记每次都是这样(有点像马丁的解决方案)。
恐怕我不太擅长 awk,所以我无法在这方面提供帮助 -
这些页面可能会有所帮助 -
http://www.gnu.org/manual/gawk/html_node/ Time-Functions.html 和 http://www.computing.net/answers/unix/script-to-convert-datetime-to-seco/3795.html。
这里描述了 awk 与 gnuplot 的使用: http://t16web.lanl.gov/Kawano/gnuplot/datafile3-e.html。
然后,您可以使用正确的时间绘制第二个轴(而不是数据) - 类似于此处使用的方法: 有没有办法在 x 轴上每小时时间尺度上绘制一天的变化?< /a>
恐怕我没有时间尝试编写完整的解决方案 - 但合理的解决方案应该是可能的。
祝你好运 - 如果你有进展,请告诉我们最新情况 - 我会很感兴趣。
I originally misunderstood your problem. I think the finer resolution to the time format is a big problem with gnuplot and one that to my knowledge is not implemented.
One possible work-around would be to use awk to convert your date into the number of seconds with something like
and then just do a regular double by double plot and forget that it was every time at all (a bit like Martin's solution).
I'm afraid I am not very good with awk and so I cannot help with this bit -
these pages might help though -
http://www.gnu.org/manual/gawk/html_node/Time-Functions.html and http://www.computing.net/answers/unix/script-to-convert-datetime-to-seco/3795.html.
The use of awk with gnuplot is described here: http://t16web.lanl.gov/Kawano/gnuplot/datafile3-e.html.
You could then plot a second axis (and not the data) with the correct times - something like the method used here: Is there a way to plot change of day on an hourly timescale on the x axis?
I'm afraid I don't have time to try and write a complete solution - but something reasonable should be possible.
Good luck - keep us updated if you get something working - I would be interested.