版权声明:本文为博主原创文章,未经博主允许不得转载。保留追究法律责任,转载联系博主。交流欢迎加QQ群463339221。 https://blog.csdn.net/m0_37362454/article/details/82970790
‘NorthOutside’ 图例标识放在图框外侧上方
‘SouthOutside’ 图例标识放在图框外侧下方
‘EastOutside’ 图例标识放在图框外侧右方
‘WestOutside’ 图例标识放在图框外侧左方
‘NorthEastOutside’ 图例标识放在图框外侧右上方
‘NorthWestOutside’ 图例标识放在图框外侧左上方
‘SouthEastOutside’ 图例标识放在图框外侧右下方
‘SouthWestOutside’ 图例标识放在图框外侧左下方
(以上几个将图例标识放在框图外)
‘Best’ 图标标识放在图框内不与图冲突的最佳位置
‘BestOutside’ 图标标识放在图框外使用最小空间的最佳位置
bbox_to_anchor:表示legend的位置,前一个表示左右,后一个表示上下。当使用这个参数时。loc将不再起正常的作用,ncol=3表示图例三列显示
具体做法如下
box = ax1.get_position()
ax1.set_position([box.x0, box.y0, box.width , box.height* 0.8])
首先按上面的方式,如果你想将图例放上面就box.height*0.8,放右边就box.width*0.8其它方式一样。同时配合下面来使用。
ax1.legend(loc='center left', bbox_to_anchor=(0.2, 1.12),ncol=3)
- 1