3 回答

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超13個(gè)贊
這是進(jìn)行實(shí)時(shí)繪圖的一種方法:將繪圖作為圖像陣列,然后將圖像繪制到多線程屏幕。
使用pyformulas屏幕(~30 FPS)的示例:
import pyformulas as pf
import matplotlib.pyplot as plt
import numpy as np
import time
fig = plt.figure()
screen = pf.screen(title='Plot')
start = time.time()
for i in range(10000):
t = time.time() - start
x = np.linspace(t-3, t, 100)
y = np.sin(2*np.pi*x) + np.sin(3*np.pi*x)
plt.xlim(t-3,t)
plt.ylim(-3,3)
plt.plot(x, y, c='black')
# If we haven't already shown or saved the plot, then we need to draw the figure first...
fig.canvas.draw()
image = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
image = image.reshape(fig.canvas.get_width_height()[::-1] + (3,))
screen.update(image)
#screen.close()
免責(zé)聲明:我是pyformulas的維護(hù)者

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個(gè)贊
我認(rèn)為看看這與matplotlib FuncAnimation的比較會(huì)有所幫助。由于這也繪制了matplotlib figure(fig.canvas.draw()),它肯定不會(huì)更快
- 3 回答
- 0 關(guān)注
- 3517 瀏覽
添加回答
舉報(bào)