2013-04-04 51 views
-4

我試圖實現以實時方式繪製數據的應用程序。我嘗試了一些我在this question中找到的代碼,但它不起作用。該圖在for循環之前繪製了一個結果,在for循環完成時繪製了一個結果python/pyqt中的Iinteractive實時繪圖

這是在Ubuntu中從Python解釋器運行的。

我指的是代碼:

import numpy as np 
import matplotlib.pyplot as plt 

plt.ion() 
mu, sigma = 100, 15 
fig = plt.figure() 
x = mu + sigma*np.random.randn(10000) 
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='green', alpha=0.75) 
for i in range(50): 
    x = mu + sigma*np.random.randn(10000) 
    n, bins = np.histogram(x, bins, normed=True) 
    for rect,h in zip(patches,n): 
     rect.set_height(h) 
    fig.canvas.draw() 

回答

0

問題的出現是因爲後端。我有Qt4Agg和其更改爲TkAgg後,它的工作..不知道爲什麼Qt4Agg做不值得,但...

改變後端我不得不編輯/ etc/matplotlibrc文件

編輯:

發現了關於Qt4Agg的信息,而不是調用draw(),應該暫停它,只要調用pause(0.001)就可以了,這裏暫停1ms。在這個

https://github.com/matplotlib/matplotlib/issues/177

信息