简体   繁体   English

错误地将图例放置在python大熊猫中

[英]Incorrectly placed legend in python pandas

I am using the foll. 我正在使用foll。 code to plot legend in python pandas , but it is not showing up correctly: 代码在python pandas中绘制图例,但未正确显示:

# Create plot
fig = plt.figure()
plt.rc('legend',**{'fontsize':8})
ax = df.resample('M', how='mean').plot(colormap=cols)

# Create a legend with transparent box around it
leg = plt.legend(fancybox = None, bbox_to_anchor=(0.5, -0.02), ncol=3)
leg.get_frame().set_linewidth(0.5)
leg.get_frame().set_alpha(0.5)
ax.set_ylabel('Percentiles')

# Place legend in right place and output
fig.subplots_adjust(bottom=0.2)

How do I fix this? 我该如何解决? I want legend to be outside of plot but visible and not partly cut off. 我希望图例不在情节中,但可见且不被部分截断。

在此处输入图片说明

The second parameter in bbox_to_anchor controls the y-axis. bbox_to_anchor中的第二个参数控制y轴。 Try changing it, eg: 尝试更改它,例如:

leg = plt.legend(fancybox = None, bbox_to_anchor=(0.5, -0.04), ncol=3)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM