[英]Minimalistic Real-Time Plotting in Python
我一直在广泛使用python从各种外部设备中提取数据(从arduinos到示波器),我正在寻找一种简单的方法来绘制内容。
关于堆栈溢出的类似问题已经有了一些答案: wxPython的最佳实时绘图小部件是什么?
大部分都指向Eli Bendersky的这段精美代码http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/
但是代码的范围远比我正在寻找的范围复杂得多。 我正在寻找一些相当简约的东西,它只是在从源流式传输时实时绘制数据 - 它不需要GUI,单选按钮,旋钮和滑块,或类似的东西。
似乎在循环中调用pylab.plot()或pylab.show()等解决方案似乎没有给出正确的行为。
有没有人有建议?
要使用实时绘图,您需要将信号发送到GUI循环。 如果您使用交互模式(Ipython),那么您可能也想使用线程。
我已经编写了一些装饰器来以非常简单和干净的方式处理GUI和线程。 他们为QT后端工作。 https://gist.github.com/Vrekrer/106c49a3ae6d420937aa
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.