[英]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.