python - 图例无法正确放置数据和标签
问题描述
我有来自两个不同数据框的数据。
ice_data_dates
Date 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 max_value min_value
Date
01 Jan 12.896 13.353 12.959 13.011 13.073 12.721 12.643 12.484 12.876 13.102 13.353 12.484
02 Jan 12.915 13.421 12.961 13.103 13.125 12.806 12.644 12.600 12.956 13.075 13.421 12.600
03 Jan 12.926 13.379 13.012 13.116 13.112 12.790 12.713 12.634 12.959 13.176 13.379 12.634
04 Jan 13.051 13.414 13.045 13.219 13.051 12.829 12.954 12.724 13.047 13.187 13.414 12.724
05 Jan 13.176 13.417 13.065 13.148 13.115 12.874 12.956 12.834 13.098 13.123 13.417 12.834
ice_data_climo
DOY AverageExtent StdDeviation 10th 25th 50th 75th 90th
0 1 13.778 0.407 13.183 13.479 13.823 14.095 14.257
1 2 13.842 0.434 13.201 13.538 13.886 14.164 14.321
2 3 13.891 0.443 13.264 13.502 13.884 14.283 14.369
3 4 13.930 0.443 13.284 13.590 13.925 14.288 14.417
4 5 13.978 0.437 13.349 13.617 14.036 14.304 14.470
我在下面画了一个线图。
fig, ax = plt.subplots()
ice_data_dates.plot(figsize=(20,12), lw=3, fontsize=16, ax=ax, grid=True)
for line in ax.get_lines():
if line._label == '2020':
line.set_linewidth(6)
line.set_color('k')
legend=['2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '1981-2010 Average', 'Interquartile Range', 'Interdecile Range']
plt.text(0.80, 0.97, "Sea Ice Extent for" + " " +str(plot_date)+ "=%f $10^6$ km" %ice_today, fontsize=16, horizontalalignment='center', verticalalignment='center', transform=ax.transAxes)
plt.text(0.80, 0.94, "Min Sea Ice Extent for" + " " +str(plot_date)+ "=%f $10^6$ km" %min_today, fontsize=16, horizontalalignment='center', verticalalignment='center', transform=ax.transAxes)
plt.text(0.80, 0.91, "Max Sea Ice Extent for" + " " +str(plot_date)+ "=%f $10^6$ km" %max_today, fontsize=16, horizontalalignment='center', verticalalignment='center', transform=ax.transAxes)
plt.plot(ice_climo['DOY'], ice_climo['AverageExtent'], c='k', lw=3, linestyle='--')
plt.fill_between(ice_climo['DOY'],ice_climo['AverageExtent'],ice_climo['25th'], color='dimgray', alpha=0.7)
plt.fill_between(ice_climo['DOY'],ice_climo['AverageExtent'],ice_climo['10th'], color='lightgray', alpha=0.5)
plt.fill_between(ice_climo['DOY'],ice_climo['AverageExtent'],ice_climo['75th'], color='dimgray', alpha=0.7)
plt.fill_between(ice_climo['DOY'],ice_climo['AverageExtent'],ice_climo['90th'], color='lightgray', alpha=0.5)
plt.title('Arctic Sea Ice Extent for the Latest 10 Years', fontsize=22, weight='bold' )
ax.set_xlabel("Date", weight='bold', fontsize=16)
ax.set_ylabel("Sea Ice Extent ($10^6$ km)", weight='bold', fontsize=16)
ax.legend(legend, loc='lower left', fontsize=20)
plt.axvline(x=plot_day, c='k', linestyle='--')
这产生了这个数字。
但是,如果您注意到,传说由于某种原因搞砸了。1981-2010 年的平均值应该是一条黑色虚线,四分位数/十分位数的平均值应该是不同的灰色阴影。我到底在搞砸什么传说?
解决方案
推荐阅读
- javascript - 如何在 JavaScript 中读取本地 /proc 文件?
- go - 如何在很短的时间间隔内/同时进行多个查询
- spss - 应用多个权重
- php - 在php的curl方法中上传文件的问题
- docker - 如何在 Docker Compose 中使用 Docker 构建机密?
- python - 如何编写具有多个参数/参数的装饰器?
- reactjs - 字体真棒和反应毛的问题
- flutter - Flutter - 动画小部件,仅触发一次动画,但在小部件上获取数据更新
- javascript - react-native-datetimepicker 更改文本颜色
- python - python threading - 多参数和返回