2015-10-05 15 views
0

我正在使用foll。代碼在python熊貓中繪製圖例,但它沒有正確顯示:在python熊貓中錯誤地放置圖例

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

我該如何解決這個問題?我希望傳說在情節之外,但可以看到,而不是部分切斷。

enter image description here

回答

1

第二個參數在bbox_to_anchor控制y軸。嘗試改變它,例如:

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

謝謝!有沒有辦法讓它居中對齊?而不是目測bbox_to_anchor參數? – user308827