Python Matplotlib添加2个动态标题组件



我有6个子情节,需要2个动态标题组件,我可以为1个进行编码,但在搜索文献后,我不知道如何更改下面的代码,在同一行添加第二个动态标题分量。这是我的for循环,用于生成下面有"plt.title…"行的6个子图:

list = [0,1,2,3,4,5]
now = datetime.datetime.now()
currm = now.month
import calendar
fig, ax = plt.subplots(6)
for x in list: 
dam = DS.where(DS['time.year']==rmax.iloc[x,1]).groupby('time.month').mean()#iterate by index of 
column "1" or the years
dam = dam.sel(month=3)#current month mean 500
dam = dam.sel(level=500)
damc = dam.to_array()
lats = damc['lat'].data
lons = damc['lon'].data
#plot data
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines(lw=1)
damc = damc.squeeze()
cnplot = plt.contour(lons,lats,damc,cmap='jet')
plt.title('Mean 500mb Hgt + Phase {} 2020'.format(calendar.month_name[currm-1]))
plt.show()
#plt.clf()

我需要在循环中的"+"和上面的"相位"行之间的"plt.title…"中添加该列表中的每一个。。。?

tindices = ['SOI','AO','NAO','PNA','EPO','PDO']

感谢您的帮助!

尝试逐个访问tindices并将其传递给标题

plt.title('Mean 500mb Hgt + {} Phase {} 2020'.format(tindices[x], 
calendar.month_name[currm-1]))

最新更新