图例的注释使用方法如下:
plt.legend(loc=’, title='',fontsize=12, frameon=True, fancybox=True, framealpha=0.2, borderpad=0.3, ncol=1, markerfirst=True, markerscale=1, bbox_to_anchor='',numpoints=1, handlelength=3.5,shadow='')
其中:
- loc 设置图例的位置,可取值:‘best’=0,‘upper right’=1,‘upper left’=2,‘lower left’=3,‘lower right’=4,‘right’=5,‘center left’=6,‘center right’=7,‘lower center’=8,‘upper center’=9,‘center’=10;
- ncol 设置图例的数量,默认值为 1
- bbox_to_anchor 设置图例的位置,与 loc 配合使用
例如:
ax.legend(loc='lower center', bbox_to_anchor=(0.5, 1),ncol=3)
图例效果如下:
bbox_to_anchor 的其他设置方法如图所示: