1 回答
TA贡献1757条经验 获得超7个赞
你lines在每个情节之后重新定义。也许你想要:
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, ....)
但是,我认为将标签传递给更干净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()
添加回答
举报