【发布时间】:2018-04-30 10:14:43
【问题描述】:
我正在尝试绘制在海中漂流的点。以下代码有效,但也绘制了先前绘图的所有点:
Duration = 6 #hours
plt.figure(figsize=(20,10))#20,10
map = Basemap(width=300000,height=300000,projection='lcc',
resolution='c',lat_0=51.25,lon_0=-4)#lat_0lon_0 is left under
map.drawmapboundary(fill_color='turquoise')
map.fillcontinents(color='white',lake_color='aqua')
map.drawcountries(linestyle='--')
x=[]
y=[]
for i in range (0,Duration):
x,y = map(Xpos1[i],Ypos1[i])
map.scatter(x, y, s=1, c='k', marker='o', label = 'Aurelia aurita', zorder=2)
plt.savefig('GIF10P%d' %i)
Xpos1 和 Ypos1 是掩码数组的列表。列表中的每个数组的长度为 10,因此每个地图中应绘制 10 个点:
Xpos1=[[latitude0,lat1,lat2,lat3,..., lat9],
[latitude0,lat1,lat2,lat3,..., lat9],...]
每张图片应该有 10 分,但最后一张是所有地图的组合(所以 60 分)。 我如何仍然获得 6 张地图,每张只有 10 分?
编辑: 当我使用来自matplotlib.pyplot will not forget previous plots - how can I flush/refresh? 的答案时,我得到了错误
ValueError: Can not reset the axes. You are probably trying to re-use an artist in more than one Axes which is not supported
当我使用来自How to "clean the slate"?的答案时,会弹出一个类似的错误 即,
plt.clf()
plt.cla()#after plt.show()
非常感谢任何帮助!
【问题讨论】:
-
是只有最后一张图是所有图的组合,还是除了第一张以外的所有图都是之前所有图的组合?
-
另外,请说明
map对象(在其上调用scatter方法)的来源。 -
scatter似乎在现有情节中添加了新点。您可能需要在每次保存后清除或重新创建它。 -
尝试将 for 循环外的内容移到顶部。
-
作为一个小点
map是一个关键字 - 所以避免它作为变量 - 在你为问题添加额外细节之前让我感到困惑
标签: python loops matplotlib