python 中的快速而肮脏的条形图?
我有一些 python 代码,它经常接收一条包含时间戳和边缘转换(从低到高或从高到低)的消息。 我想在条形图上绘制每个转换的图表,以便以最少的努力快速而直观地可视化数字波形。
你能推荐一些可以让这变得简单的方法或包吗?
我也不反对以 csv 等格式导出数据并将其加载到另一个程序中(如果这样更容易的话)。
编辑:
尝试过 CairoPlot:
>>> data = [(10, 0), (11, 1), (12.5, 0), (15, 1)]
>>> def fn(t):
... for d in data:
... if t > d[0]:
... return d[1]
... return data[-1][1]
...
>>> CairoPlot.function_plot( 'tester.png', data, 500, 300, discrete = True, h_bounds=( data[0][0],data[-1][0]), step = 1 )
这将我的 CPU 固定在 100% 超过 10 分钟,并且一直在消耗内存。 我在它用完所有交换空间之前杀死了它。 我做错了什么还是 CairoPlot 坏了?
进一步编辑:
我现在使用 CairoPlot 有了一些更可行的东西,大致基于上面的代码。 然而,由于分辨率的原因,它并不完美:我可能需要高达数十纳秒 (1e-8) 的分辨率才能捕获一些较短的脉冲。 对于多秒图表,使用此方法需要非常很长时间。
I have some python code that receives a message every so often containing a timestamp and an edge transition, either low-to-high, or high-to-low. I'd like to graph each transition on a stripchart for a quick and dirty visualization of the digital waveform with the minimal amount of effort.
Can you recommend any methods or packages that would make this easy?
I'm also not opposed to exporting the data in, for instance, csv format and loading it into another program if that would be easier.
Edit:
Tried CairoPlot:
>>> data = [(10, 0), (11, 1), (12.5, 0), (15, 1)]
>>> def fn(t):
... for d in data:
... if t > d[0]:
... return d[1]
... return data[-1][1]
...
>>> CairoPlot.function_plot( 'tester.png', data, 500, 300, discrete = True, h_bounds=( data[0][0],data[-1][0]), step = 1 )
This pinned my CPU at 100% for more than 10 minutes and was steadily eating memory. I killed it before it used up all of swap. Am I doing something wrong or is CairoPlot just broken?
Further edit:
I now have something more workable using CairoPlot, based loosely on the above code. However, it's not perfect because of the resolution: I may need up to tens of nanoseconds (1e-8) resolution in order to catch some of the shorter pulses. For a multi-second graph, this takes a very long time with this method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我自己没有使用过它,但也许 开罗情节值得一看。
I haven't use it myself, but perhaps Cairo Plot is worth taking a look at.
Matplotlib 可能有效。 看看这个条形图演示。
Matplotlib might work. Take a look at this strip chart demo.
您可以尝试使用 CairoPlot:
有关详细信息,请查看 CairoPlot
编辑:
我在这里不明白你的函数 fn(t) 。 function_plot 的想法是绘制函数而不是向量。
要绘制这些点,您可以按以下方式使用 function_plot:
我想这对于 100% 固定 CPU 来说会起作用
,这不应该发生......我将在今天晚些时候查看它。 谢谢你的指点
\o_
you may try using CairoPlot:
For more information, check CairoPlot
Edit:
I didn't understand your function fn(t) here. The idea of the function_plot is to plot a function not a vector.
To plot those points, you could use function_plot on this way:
I guess that will work
For the 100% pinning CPU, that shouldn't happen... I'll take a look at it later today. Thanks for pointing it
\o_
http://bitworking.org/projects/sparklines/ 为您提供了一个小图表。
http://bitworking.org/projects/sparklines/ provides a tiny graph for you.
GnuPlot 是一个古老的可靠答案,有很多选项,可以轻松绘制图表。 我相信有 python 绑定,但导出数据并通过常规 gnuplot 运行它可能更容易。 这是一个古老的快速入门文档。
我还使用 matplotlib 在处理较大的数据量方面取得了巨大成功。
GnuPlot is a the old reliable answer here, easy graphing with lots of options. I believe there are python bindings but it's probably easier to export your data and run it through regular gnuplot. Here's an ancient quick start doc for it.
I'm also using matplotlib with great success for larger data sizes.
对于仅使用 tkinter 的实时条形图应用程序(不需要外部包),请参阅 wxPython 最好的实时绘图小部件是什么?。
如果我理解您的问题,您正在以纳秒分辨率时间戳实时接收消息,但您不希望每秒看到 10^9 条消息。 如果平均消息速率较低(每秒 100 条消息或更少),我会忽略时间戳并一次绘制一条消息的转换。 如果图形时间尺度为每像素 10 毫秒,则将在 40 毫秒内绘制 4 个过渡,但至少您不会错过看到发生的事情。
For a realtime stripchart application using only tkinter (no external packages required), see What is the best real time plotting widget for wxPython?.
If I understand your question, you are receiving messages in realtime with nanosecond resolution timestamps, but you don't expect to see 10^9 messages per second. If the average message rate is low (100 messages per second or fewer), I'd just ignore the timestamp and plot the transitions one message at a time. If the graph timescale is 10ms per pixel, 4 transitions would be drawn over 40ms, but at least you wouldn't miss seeing that something happened.