美文网首页
matplotlib:如何把图例画在图外

matplotlib:如何把图例画在图外

作者: Ryan96 | 来源:发表于2020-02-09 17:51 被阅读0次

有时候图例会挡住柱状图或者别的展示
可以显示在图外

# ax1是子图的名字 自己改为对应的子图就可以了
#需要改的数值为第二行的0.8和第三行0.2和1.12,需要自己试着调
#ncol 表示图例为3列,改为1就是1列竖着一长条
box = ax1.get_position()
ax1.set_position([box.x0, box.y0, box.width , box.height* 0.8])
ax1.legend(loc='center left', bbox_to_anchor=(0.2, 1.12),ncol=3)

相关文章

网友评论

      本文标题:matplotlib:如何把图例画在图外

      本文链接:https://www.haomeiwen.com/subject/tljnxhtx.html