Python Matplotlib 添加2个动态标题组件
Python Matplotlib Add 2 Dynamic Title Components
我有 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()
我需要将循环中此列表中的每一个添加到“+”和上面的单词 "Phase" 行之间的 "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]))
我有 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()
我需要将循环中此列表中的每一个添加到“+”和上面的单词 "Phase" 行之间的 "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]))