3 回答
TA贡献1871条经验 获得超13个赞
这是进行实时绘图的一种方法:将绘图作为图像阵列,然后将图像绘制到多线程屏幕。
使用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()
免责声明:我是pyformulas的维护者
TA贡献1946条经验 获得超3个赞
我认为看看这与matplotlib FuncAnimation的比较会有所帮助。由于这也绘制了matplotlib figure(fig.canvas.draw()),它肯定不会更快
- 3 回答
- 0 关注
- 3448 浏览
添加回答
举报