【问题标题】:using matplotlib's quiver in a loop efficiently在循环中有效地使用 matplotlib 的 quiver
【发布时间】:2013-10-29 00:13:10
【问题描述】:

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

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

程序每次循环都会占用更多的内存。有没有办法解决这个问题?比如在每个循环结束时完全删除倒钩?

【问题讨论】:

  • 你为什么画它们然后又去掉它们?加速绘图的一种方法是先构建它们,然后在最后调用 draw,通过调用 ioff() 将交互模式设置为关闭。你的例子远非如此,但由于它不完整,很难猜出你想要什么。

标签: python matplotlib


【解决方案1】:

如果您只需要重置 (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 模块,它会为您处理很多细节。

【讨论】:

    猜你喜欢
    • 2017-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-26
    • 1970-01-01
    • 2020-07-10
    • 1970-01-01
    相关资源
    最近更新 更多