簡體   English   中英

錯誤地將圖例放置在python大熊貓中

[英]Incorrectly placed legend in python pandas

我正在使用foll。 代碼在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)

我該如何解決? 我希望圖例不在情節中,但可見且不被部分截斷。

在此處輸入圖片說明

bbox_to_anchor中的第二個參數控制y軸。 嘗試更改它,例如:

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