在matplotlib中的绘图之间保持地图覆盖 [英] Keeping map overlay between plots in matplotlib
问题描述
我正在根据底图在地图上创建一系列纬度/经度散点图.我计划使用不同的经/纬度数据创建数千个图.为了节省时间,我只想绘制一次地图叠加层:
I am creating a series of lat/long scatterplots on a map from basemap. I am planning on creating thousands of plot, with different lat/long data. To save time I wanted to draw the map overlay only once:
map = Basemap(epsg=3395, projection='merc', lat_0=59.45, lon_0=10.5,
resolution = 'h',
llcrnrlon=minlong, llcrnrlat=minlat,
urcrnrlon=maxlong, urcrnrlat=maxlat
map.arcgisimage(service='ESRI_Imagery_World_2D', xpixels=3000, verbose=True)
但是,在绘制新散点图之前,我找不到清除散点图的方法.
However, I find no way of clearing my previous scatterplot before plotting a new one.
for each set in sets:
x = set[0]
y = set[1]
x,y = map(x,y)
plt.scatter(x,y, s=2.5, alpha=1, color=c, edgecolors='none')
plt.savefig('title.png', format='png', bbox_inches='tight', dpi=500)
如果我执行以下操作:
plt.clf()
或
plt.close()
我必须重绘地图.如果我什么都没有,那么将绘制上一次迭代的散点图.那么,如何删除所有散点图数据,但保留地图数据呢?
I have to redraw my map. If I don't have anything, the scatter plot from the previous iteration are plotted. So how do I remove all scatterplot data, but keeping the map data?
推荐答案
仅更改散点图的数据怎么办?
What about just changing the data of your scatter plot?
# save an empty scatter plot
scat = plt.scatter([], [], s=2.5, alpha=1, color=c, edgecolors='none')
for each set in sets:
# The data needs to be written as [(x1, y1), (x2, y2), ...]
scat.set_offsets([xy for xy in zip(x, y)])
plt.savefig("...")
这篇关于在matplotlib中的绘图之间保持地图覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!