Matplotlib:将默认图例 loc 和图例 bbox 更改为锚点 [英] Matplotlib: change default legend loc and legend bbox to anchor

查看:92
本文介绍了Matplotlib:将默认图例 loc 和图例 bbox 更改为锚点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次用pandas在matplotlib中绘图时,为了将图例放在图形之外,我必须执行以下操作:

Each time to plot in matplotlib with pandas, in order to put the legend outside of figure, I have to do something like:

single_obj_trading_curve_instrument_toppercentile.plot().legend(loc = "center left",bbox_to_anchor = (1,0.5))

后面的部分

.legend(loc = "center left",bbox_to_anchor = (1,0.5))

太重复了...有没有办法将其设置为默认值?谢谢,

is too repetitive... Is there a way to set this to default? Thank you,

推荐答案

您可以设置

import matplotlib.pyplot as plt
plt.rcParams["legend.loc"] = "center left"

但是你仍然需要定义 bbox

However you would then still need to define the bbox

df.plot().legend(bbox_to_anchor = (1,0.5))

这篇关于Matplotlib:将默认图例 loc 和图例 bbox 更改为锚点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆