如何让 Basemap 与时间片的 xarray 绘图一起使用
How to get Basemap to work with xarray plotting for time slices
我需要使用 Basemap 在 shapefile 上绘制一个 xarray.DataArray 对象。
源数据包含几天的数据。
我希望使用底图在 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 中的每个轴创建一个底图。
这个想法应该是
grid = data.plot(...)
for ax in grid.axes.flatten():
map = Basemap(..., ax=ax)
map.readshapefile(...)
plt.show()
我需要使用 Basemap 在 shapefile 上绘制一个 xarray.DataArray 对象。
源数据包含几天的数据。
我希望使用底图在 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 中的每个轴创建一个底图。 这个想法应该是
grid = data.plot(...)
for ax in grid.axes.flatten():
map = Basemap(..., ax=ax)
map.readshapefile(...)
plt.show()