如何为facetted xarray plot设置单个标题?

问题描述 投票:0回答:1

我需要为多个绘图设置标题,每个绘图都使用Basemap绘制。

源数据是xarray DataArray对象。该代码使用DataArray.plot()在单个图上绘制多个图。

p = da_monthly_slice.plot(levels=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31], cmap=plt.cm.Reds, x='longitude', y='latitude', col='time', col_wrap=3)

for i, ax in enumerate(p.axes.flatten()):
    ax.set_title('Month: %d' % i)
    ax.set_xlabel('Longitude')
    ax.set_ylabel('Latitude')
    map = Basemap(llcrnrlat=-39.2,urcrnrlat=-33.9,llcrnrlon=140.8,urcrnrlon=150.0,resolution='i',ax=ax)
    map.readshapefile(shapefile1, 'CFA_DISTRICT_BODY', linewidth=0.5)

fig = plt.figure()
st = fig.suptitle("Number of days for each month meeting the criteria in 2017", fontsize="large")

plt.show()

这导致两个数字分开绘制。一个用于多个图,而另一个用于仅包含标题。

如何使标题显示在同一图上的多个图的顶部?

python matplotlib matplotlib-basemap python-xarray
1个回答
0
投票

fig = plt.figure()创造了一个新的人物。删除该行。

您可以使用plt.suptitle(..)在当前图中创建标题。 或者你从FacetGrid得到的数字,它应该是p.fig

© www.soinside.com 2019 - 2024. All rights reserved.