我一直在广泛地使用python从各种外部设备(从arduinos到示波器)中提取数据,我正在寻找一种简单的方法来绘制数据。
关于堆栈溢出,已经有一些类似问题的答案:What is the best real time plotting widget for wxPython?
大多数人都指向这段由Eli Bendersky http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/编写的优秀代码。
但是代码的范围比我要找的复杂得多。我正在寻找一种相当简约的东西,它只是在数据从一个来源流出时实时绘制出来--它不需要GUI、单选按钮、旋钮和滑块,或者任何类似的东西。
看起来像在循环中调用pylab.plot()或pylab.show()这样的解决方案似乎没有给出正确的行为。
有没有人有建议?
发布于 2012-02-23 05:01:24
除了您已经找到的matplotlib示例之外,这里还有wx.lib.plot和几个答案:http://wxpython-users.1045709.n5.nabble.com/real-time-data-plots-td2344816.html
发布于 2012-02-23 04:34:07
好吧,这不是一个wxPython的答案,但是我已经使用了Chaco来做这类事情,它非常简单。有一个很好的realtime spectrum analyzer示例,它可能与您的用例相似,还有一个很好的tutorial。所以,如果你没有因为其他原因而依赖于wxPython,这可能值得一看。
发布于 2015-07-31 02:42:25
要使用实时绘图,您需要将信号发送到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) )https://stackoverflow.com/questions/9401857
复制相似问题