2017-02-16 97 views
0

我想添加填充到我的情節的左側和右側。 但是當我改變xlim和ylim;圖像變小。如何在python中添加填充圖?

我做錯了什麼?

import matplotlib.pyplot as plt 
plt.rcParams['text.usetex'] = False 
from matplotlib.font_manager import FontProperties 
import seaborn as sns 
%matplotlib inline 



df1=df['Total Acc'].round(4)*100 
labels = ['AWA','Rem', 'S1', 'S2', 'SWS', 'SX', 'ALL'] 


rows = [df1.loc[label] for label in labels] 
for row in rows: 
    row.plot(figsize=(10, 5), marker='o') 


# http://matplotlib.org/api/legend_api.html ---set_bbox_to_anchor(bbox, transform=None) 
myLegend=plt.legend(labels, bbox_to_anchor=(0., 1.15, 1., .102), prop ={'size':10}, loc=10, ncol=7, #left, bottom, width, height 
       title=r'LEARNING CURVE - Fp1_RF(20)')           
myLegend.get_title().set_fontsize('18') 


plt.ylim(97.5, 98.5) 
plt.xlim(0, 45) 

plt.xlabel('# of samples per subject') 
plt.ylabel('Accuracy') 

enter image description here

回答

1

如果您matplotlib身影是越來越修剪,你可以使用Tight Layout。詳細信息提供here

在代碼中,嘗試添加

plt.tight_layout() 

另一種選擇,你可以嘗試是使用subplots_adjust()。基本上它可以控制左側,右側,底部和頂部的默認間距以及多行和多列之間的水平和垂直間距。 Sample Example here

plt.subplots_adjust(left=0.5, right=0.5) 
+0

它們都不工作。曲線從x = 10開始。我想軸開始在0.這就是爲什麼我使用:plt.xlim(0,45)。這是行不通的。同時如果我這樣做的Y軸(plt.ylim(0,91);它的作品。 – Aizzaac