【发布时间】:2020-06-26 01:38:06
【问题描述】:
我想“下载”(保存在pickle 文件中)在cartopy 中加载的底图,以便我可以使用不同的方法在matplotlib figure 中的两个轴之一上重新绘制脚本比我用来下载图像的脚本。我需要这样做,这样我就不会在每次需要基础层时都查询 Stamen。
如何从p 那里提取数据p==<cartopy.mpl.geoaxes.GeoAxesSubplot object at 0x124210e10>
脚本 1
import matplotlib.pyplot as plt
import pickle
import cartopy.feature as cfeature
from cartopy.io.img_tiles import Stamen
def main():
tiler = Stamen('terrain-background')
mercator = tiler.crs
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax.set_extent([15.85583, 18.47056, 5.80167, 6.56194], crs=ccrs.PlateCarree())
ax.add_image(tiler, 6)
ax.coastlines('10m')
#plt.show()
pickle.dump(ax, open('map.pkl', 'wb'))
main()
脚本 2
import matplotlib.pyplot as plt
import pickle
p=pickle.load(open('map.pkl', 'rb'))
#plt.show() #works; but I want to integrate as a 2nd axis in another figure, now its own figure
fig, axes = plt.subplots(1, 2)
axes[1] = p
plt.show() #shows two axes; but axes[1] is not the map
注意:我标记了 basemap 包,因为 cartopy 会在某个时候替换它
【问题讨论】:
标签: python matplotlib-basemap cartopy