我需要使用Basemap将xarray.DataArray对象绘制到shapefile上。
源数据包含几天的数据。
我希望每个数据集都使用Basemap在shapefile上绘制。
... ...
shapefile1="./shp/CFA_DISTRICT_BODY"
# Select 3 days' datasets
da_criteria_1or0_hourly_rolled_resampled_sel_slice = da_criteria_1or0_hourly_rolled_resampled.sel(time=slice('2017-01-01', '2017-01-03'))
# Draw each day's dataset and set them drawn horizontally
p = da_criteria_1or0_hourly_rolled_resampled_sel_slice.plot(levels=[0,1,2], x='longitude', y='latitude', col='time', col_wrap=3)
# Draw the shapefile
map = Basemap(llcrnrlat=-39.2,urcrnrlat=-33.9,llcrnrlon=140.8,urcrnrlon=150.0,resolution='i')
map.readshapefile(shapefile1, 'CFA_DISTRICT_BODY', linewidth=0.5)
plt.show()
上面代码的问题只是第3天的数据集在shapefile上绘制。
你只定义一个Basemap
。这将适用于最后的活动轴。
相反,您将为FacetGrid中的每个轴创建一个Basemap。这个想法就是这样的
grid = data.plot(...)
for ax in grid.axes.flatten():
map = Basemap(..., ax=ax)
map.readshapefile(...)
plt.show()