【问题标题】:Plot subplots from xarray Dataset to AxesGrid绘制从 xarray 数据集到 AxesGrid 的子图
【发布时间】:2021-06-06 05:47:17
【问题描述】:

可以通过这种方式直接从xarray.Dataset 创建地图子图:(取自第二个示例here

p = air.isel(time=[0, 4]).plot(
    transform=ccrs.PlateCarree(),
    col="time",
    subplot_kws={"projection": ccrs.Orthographic(-80, 35)})


for ax in p.axes.flat:
    ax.coastlines()
    ax.gridlines()

但是,这对应于使用标准的matplotlib 子图,例如将AxesGrid 传递给plot 函数,以便最初对子图进行更多控制会很好。这可能吗?

【问题讨论】:

    标签: python matplotlib plot python-xarray


    【解决方案1】:

    您可以通过 ax 参数将自定义轴传递给 xarray 绘图函数,以更好地控制定义轴的方式。

    map_projection = ccrs.Orthographic(-80, 35)
    fig, axis = plt.subplots(2,2, figsize=(8,8), dpi=100, subplot_kw=dict(projection=map_projection))
    
    
    for i,ax in enumerate(axis.flatten()):
        air.isel(time=i).plot(ax=ax,
        transform=ccrs.PlateCarree())
    

    【讨论】:

    • 我在我的帖子中指定我不想使用标准子图,而是AxesGrid
    • 好的,你到底想控制什么?例如,可以使用gridspec 创建一个网格以进行更精细的调整并向网格添加轴,其中还可以包括带有cartopy 投影的轴
    猜你喜欢
    • 1970-01-01
    • 2021-05-17
    • 2020-12-06
    • 2018-01-10
    • 1970-01-01
    • 2021-08-29
    • 2021-06-14
    • 2020-02-07
    • 1970-01-01
    相关资源
    最近更新 更多