1 回答

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超7個(gè)贊
你lines在每個(gè)情節(jié)之后重新定義。也許你想要:
lines = []
for i in [26,27,28,39,30,32,84,86,87,88,96,98,99]:
line = ax.plot(years, mov_ave(fwf_tot.where(ds.ocean_basins == i).resample(TIME='1AS').sum().sum(dim=('X','Y')),5,'edges'))
# add the line to line list
lines.append(line)
ax.legend(lines, ....)
但是,我認(rèn)為將標(biāo)簽傳遞給更干凈ax.plot:
labels = ['Labrador sea','Hudson strait','Davis strait','Baffin bay', 'Lincoln sea', 'Irish sea and St. George', 'Arctic ocean', 'Barentsz sea', 'Greenland sea',
'North sea', 'Kategat', 'Skagerrak', 'Norwegian sea']
values = [26,27,28,39,30,32,84,86,87,88,96,98,99]
for i,l in zip(values, labels):
lines = ax.plot(years, mov_ave(fwf_tot.where(ds.ocean_basins == i)
.resample(TIME='1AS').sum()
.sum(dim=('X','Y')),
5,'edges'),
label=l)
plt.title('Total FWF anomalies per ocean basin (moving average)')
ax.legend()
plt.grid()
plt.show()
添加回答
舉報(bào)