gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 01:16:37 25 4
gpt4 key购买 nike

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

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

该程序在每个循环中占用更多的内存。有办法解决这个问题吗?例如在每个循环结束时完全删除倒钩?

最佳答案

如果您只需要重置 (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 figure , Visualization of 3D-numpy-array frame by frame ,

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

关于python - 有效地在循环中使用 matplotlib 的箭袋,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12169001/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com