如何为多面 xarray 图设置单个标题?
How to set a single title for facetted xarray plot?
我需要为多个图设置标题,每个图都是用底图绘制的。
源数据是一个 xarray 的 DataArray object。该代码使用 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()
这导致两个图分开画了。一个用于多个地块,而另一个仅包含标题。
如何让标题显示在同一张图的多个绘图的顶部?
fig = plt.figure()
创建一个新图形。删除该行。
您可以使用plt.suptitle(..)
在当前图中创建标题
或者你从FacetGrid
中得到的数字,应该是p.fig
.
我需要为多个图设置标题,每个图都是用底图绘制的。
源数据是一个 xarray 的 DataArray object。该代码使用 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()
这导致两个图分开画了。一个用于多个地块,而另一个仅包含标题。
如何让标题显示在同一张图的多个绘图的顶部?
fig = plt.figure()
创建一个新图形。删除该行。
您可以使用plt.suptitle(..)
在当前图中创建标题
或者你从FacetGrid
中得到的数字,应该是p.fig
.