-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()