[英]Minimalistic Real-Time Plotting in Python
I've been using python extensively to extract data from various external pieces of equipment (ranging from arduinos to oscilloscopes), and I'm looking for a simplistic way to plot stuff. 我一直在广泛使用python从各种外部设备中提取数据(从arduinos到示波器),我正在寻找一种简单的方法来绘制内容。
There's already some answers to similar questions on stack overflow: What is the best real time plotting widget for wxPython? 关于堆栈溢出的类似问题已经有了一些答案: wxPython的最佳实时绘图小部件是什么?
With most pointing to this fine piece of code by Eli Bendersky http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/ 大部分都指向Eli Bendersky的这段精美代码http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/
But the scope of the code is far more complicated that what I'm looking for. 但是代码的范围远比我正在寻找的范围复杂得多。 I'm looking for something rather minimalistic that just plots the data in real-time as it streams from a source -- it doesn't need a GUI, radio buttons, knobs and sliders, or anything like that.
我正在寻找一些相当简约的东西,它只是在从源流式传输时实时绘制数据 - 它不需要GUI,单选按钮,旋钮和滑块,或类似的东西。
It seems that solutions such as calling pylab.plot() or pylab.show() in a loop doesn't seem to give the correct behavior. 似乎在循环中调用pylab.plot()或pylab.show()等解决方案似乎没有给出正确的行为。
Does anyone have suggestions? 有没有人有建议?
Well, this isn't a wxPython answer but I've used Chaco for this sort of thing and it's pretty straight forward. 好吧,这不是一个wxPython的答案,但是我已经将Chaco用于此类事情而且非常直接。 There is a nice example of a realtime spectrum analyzer that may be similar to your use case and a nice tutorial .
有一个很好的实时频谱分析仪的例子可能类似于你的用例和一个很好的教程 。 So, if you aren't tied to wxPython for other reasons, that might be worth a look.
所以,如果你因为其他原因没有与wxPython绑定,那可能值得一看。
To use real time plotting you need to send signals to the GUI loop. 要使用实时绘图,您需要将信号发送到GUI循环。 If you use interactive mode (Ipython) then you might also like to use threads.
如果您使用交互模式(Ipython),那么您可能也想使用线程。
I have written some decorators to handle the GUI and threading in a really easy and clean way. 我已经编写了一些装饰器来以非常简单和干净的方式处理GUI和线程。 They work for the QT backend.
他们为QT后端工作。 https://gist.github.com/Vrekrer/106c49a3ae6d420937aa
https://gist.github.com/Vrekrer/106c49a3ae6d420937aa
A sample code for Ipython will look like this Ipython的示例代码如下所示
#%pylab qt
#https://gist.github.com/Vrekrer/106c49a3ae6d420937aa
import QThreadDecorators
import time
@QThreadDecorators.GUI_Safe
def myplot(x,y):
#This will plot a new line for each call (ok for an example)
plot(x, y, 'bo-')
grid(True)
@QThreadDecorators.AsQThread
def myLoop(x):
y = x * nan
for i, xi in enumerate(x):
#get some data
time.sleep(1)
y[i] = xi**2
#plot in real time
myplot(x,y)
#just call the function and it will run on a thread
myLoop( arange(20) )
除了你发现的matplotlib例子之外,还有wx.lib.plot和几个答案: http ://wxpython-users.1045709.n5.nabble.com/real-time-data-plots-td2344816.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.