第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 For 循環(huán) Matplotlib 中創(chuàng)建子圖

在 For 循環(huán) Matplotlib 中創(chuàng)建子圖

catspeake 2022-10-05 17:51:04
我正在嘗試使用 matplotlib 制作 3,2 子圖,但在閱讀文檔后我不明白如何執(zhí)行此操作,因為它適用于我的代碼,如下所示:import pandas as pdfrom sys import exitimport numpy as npimport matplotlib.pyplot as pltimport datetimeimport xarray as xrimport cartopy.crs as ccrsimport calendarlist = [0,1,2,3,4,5]now = datetime.datetime.now()currm = now.monthimport calendarfig, axes = plt.subplots(nrows=3,ncols=2)fig.subplots_adjust(hspace=0.5)fig.suptitle('Teleconnection Pos+ Phases {} 2020'.format(calendar.month_name[currm-1]))#for x in list: #for ax, x in zip(axs.ravel(), list):for x, ax in enumerate(axes.flatten()):        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()        ax.contour(lons,lats,damc,cmap='jet')        ax.set_title(tindices[x])        plt.show()#plt.clf()我已經(jīng)嘗試了多個選項,其中一些在評論上方,我無法讓子圖顯示在我期待的 3,2 子圖中。我只得到單個地塊。我在下面的 for 循環(huán)中包含了第一個圖,您可以看到它沒有繪制在 3,2 子圖區(qū)域內(nèi):[![enter image description here][1]][1]帶有“ax.contour”的行可能是問題,但我不確定。非常感謝,下面是我的目標子圖區(qū)域:[![enter image description here][1]][1]
查看完整描述

1 回答

?
www說

TA貢獻1775條經(jīng)驗 獲得超8個贊

沒有可重現(xiàn)的樣本數(shù)據(jù),以下無法進行測試。但是,您的循環(huán)分配了一個新的ax并且不使用ax正在迭代的對象。此外,plt.show()被放置在循環(huán)內(nèi)。考慮以下調整


for x, ax in enumerate(axes.flatten()):

    ...

    ax = plt.axes(projection=ccrs.PlateCarree())

    ...

    plt.show()

考慮將投影放在循環(huán)內(nèi)的plt.subplots然后索引中:axes


fig, axes = plt.subplots(nrows=3, ncols=2, subplot_kw={'projection': ccrs.PlateCarree()})

fig.subplots_adjust(hspace=0.5)

fig.suptitle('Teleconnection Pos+ Phases {} 2020'.format(calendar.month_name[currm-1]))


axes = axes.flatten()


for x, ax in enumerate(axes):

        dam = DS.where(DS['time.year']==rmax.iloc[x,1]).groupby('time.month').mean()


        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


        axes[x].coastlines(lw=1)

        damc = damc.squeeze()

        axes[x].contour(lons, lats, damc, cmap='jet')

        axes[x].set_title(tindices[x])


plt.show() 

plt.clf()


查看完整回答
反對 回復 2022-10-05
  • 1 回答
  • 0 關注
  • 191 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號