有效地在循环中使用matplotlib的颤动 [英] using matplotlib's quiver in a loop efficiently
本文介绍了有效地在循环中使用matplotlib的颤动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用循环在底图上生成矢量场,如下所示:
I'm using a loop to generate vector fields on a basemap as such:
for i in range(365):
barbs = m.quiver(x, y, u[i, :], v[i, :], scale = 100)
plt.draw()
barbs.remove()
程序在每次循环中都占用更多的内存.有没有办法解决这个问题?例如在每个循环结束时完全删除倒钩?
The program takes drastically more memory with every loop. Is there a way to get around this? Such as deleting barbs entirely at the end of each loop?
推荐答案
如果只需要重置 (u,v) 组件可以使用 barb.set_UVC(newU,newV,newC)
在循环内.
If you only need to reset the (u,v) components you can use barb.set_UVC(newU,newV,newC)
inside the loop.
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:复制底图或删除数据来自图,3D-numpy的可视化- 逐帧数组,
如果您要创建动画,请查看matplotlib的
If you are trying to create an animation, look in to the animation
module of matplotlib, it takes care of a lot of the details for you.
这篇关于有效地在循环中使用matplotlib的颤动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文