有效地在循环中使用matplotlib的箭袋

时间:2012-08-28 23:33:52

标签: python matplotlib

我正在使用循环在底图上生成矢量字段:

for i in range(365):
     barbs = m.quiver(x, y, u[i, :], v[i, :], scale = 100)
     plt.draw()
     barbs.remove()

每个循环都会占用大量内存。有办法解决这个问题吗?比如在每个循环结束时完全删除倒钩?

1 个答案:

答案 0 :(得分:4)

如果您只需要重置(u,v)组件,可以在循环中使用barb.set_UVC(newU,newV,newC)

barbs = m.quiver(x, y, u[0, :], v[0, :], scale = 100)
for i in range(365):
     barbs.set_UVC(u[i,:],v[i,:])
     #save the figure or something

另见Python: copy basemap or remove data from figureVisualization of 3D-numpy-array frame by frame

如果您正在尝试创建动画,请查看matplotlib的animation模块,它会为您处理很多细节。

相关问题