python - 如何让 Basemap 与时间片的 xarray 绘图一起使用

标签 python matplotlib matplotlib-basemap python-xarray

我需要使用 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 上。

enter image description here

最佳答案

您只定义一个Basemap。这将适用于最后一个事件轴。

相反,您将为 FacetGrid 中的每个轴创建一个 basemap 。 这个想法是沿着

grid = data.plot(...)

for ax in grid.axes.flatten():
    map = Basemap(..., ax=ax)
    map.readshapefile(...)

plt.show()

关于python - 如何让 Basemap 与时间片的 xarray 绘图一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54757466/

相关文章:

Python无法识别环境变量

python - 纬度/经度数据点未显示在 basemap 图上

python - Pandas 数据框使用列作为行

python - 选择 numpy 数组,使最后一个元素为 1

python - python 中的轴选项

matplotlib - 使用 kind reg 更改 seaborn pairplot 中的标记大小

python - 将 mpl_toolkits.basemap Canvas 添加到 Pyside

python - 将文本注释到轴并对齐为圆

python - 为什么在使用这个 lambda 函数时 .issubset(x) 中应该有一个 x?

python - 如何更改 matplotlib 中的轴标签?