Matplotlib:将默认图例loc和图例bbox更改为锚点

时间:2017-11-03 14:20:50

标签: python matplotlib

每次使用pandas在matplotlib中绘图时,为了将图例放在图中,我必须做类似的事情:

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))

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

1 个答案:

答案 0 :(得分:1)

您可以设置

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

但是,您仍然需要定义bbox

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