具有更高时间精度的 gnuplot 替代方案

发布于 2024-10-13 20:13:02 字数 504 浏览 5 评论 0原文

目前我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

无语# 2024-10-20 20:13:02

根据 gnuplot 4.6 手册,它在“时间/日期说明符”(gnuplot 4.6 PDF 第 114 页)下指出:

%S - 第二个,输出为整数 0–60,输入为(双精度)

这意味着在读取诸如 2013-09-16 09:56:59.412 之类的时间戳时,将包含小数部分作为 %S 说明符的一部分。这样的时间戳将被正确处理:

set timefmt "%Y-%m-%d %H:%M:%S"
set datafile separator ","
plot "timed_results.data" using 1:2 title 'Results' with lines

并提供如下数据:

2013-09-16 09:56:53.405,10.947
2013-09-16 09:56:54.392,10.827
2013-09-16 09:56:55.400,10.589
2013-09-16 09:56:56.394,9.913
2013-09-16 09:56:58.050,11.04

According to the gnuplot 4.6 manual it states, under "Time/date specifiers" (page 114 of the gnuplot 4.6 PDF):

%S - second, integer 0–60 on output, (double) on input

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:

set timefmt "%Y-%m-%d %H:%M:%S"
set datafile separator ","
plot "timed_results.data" using 1:2 title 'Results' with lines

and fed with data like:

2013-09-16 09:56:53.405,10.947
2013-09-16 09:56:54.392,10.827
2013-09-16 09:56:55.400,10.589
2013-09-16 09:56:56.394,9.913
2013-09-16 09:56:58.050,11.04
古镇旧梦 2024-10-20 20:13:02

您可以使用 或 设置刻度格式

set format x '%.6f'

(也许,我还没有尝试过,因为我现在更喜欢使用 Matplotlib< /a> 并且我的机器上没有安装 gnuplot):(

set timefmt "%Y-%m-%d-%H:%M:%.6S"

注意与 %S 格式字符串一起指定的位数)。

更多详细信息可以在优秀的 不太常见的问题

You can set the ticks format with

set format x '%.6f'

or (maybe, I have not tried it, as I now prefer to use Matplotlib and do not have gnuplot installed on my machines):

set timefmt "%Y-%m-%d-%H:%M:%.6S"

(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.

摘星┃星的人 2024-10-20 20:13:02

我使用 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 中执行以下操作:

set datafile separator ','
plot "test.csv" using 1:3 with lines

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:

set datafile separator ','
plot "test.csv" using 1:3 with lines
酒与心事 2024-10-20 20:13:02

我最初误解了你的问题。我认为时间格式的更精细分辨率是 gnuplot 的一个大问题,据我所知,这个问题尚未实现。

一种可能的解决方法是使用 awk 将日期转换为秒数

plot  "<awk 'your_awk_one_liner' file1.dat" with lines

,然后只需执行常规的双倍绘图,然后忘记每次都是这样(有点像马丁的解决方案)。
恐怕我不太擅长 awk,所以我无法在这方面提供帮助 -
这些页面可能会有所帮助 -
http://www.gnu.org/manual/gawk/html_node/ Time-Functions.htmlhttp://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

plot  "<awk 'your_awk_one_liner' file1.dat" with lines

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文