2015-10-29 46 views
1

使用matplotlib 1.4.3和下面的代碼,數字和suptitle顯示正確,但是保存後,suptitle被刪除。Matplotlib不保存suptitle

true_vals = [1,2,3] 

f, ax_arr = plt.subplots(1,3,figsize=(15,5)) 
ax_arr = ax_arr.reshape(-1) 
f.suptitle("This is my suptitle\nThis is the second line", fontsize=20, y=1.1) 
# y is set to 1.1 to keep the second line in the suptitle from hitting the top of the subplots. 

for idx, i in enumerate(true_vals): 
    ax_arr[idx].boxplot(data[:,idx], labels=i) 

f.savefig('suptitle_test.pdf', dpi=f.dpi) 

回答

2

Using the advice given here

添加以下到savefig命令會產生一種緊張的情節,保持suptitle在保存的數字:

true_vals = [1,2,3] 

f, ax_arr = plt.subplots(1,3,figsize=(15,5)) 
ax_arr = ax_arr.reshape(-1) 
my_suptitle = f.suptitle("This is my suptitle\nThis is the second line", fontsize=20, y=1.1) 
# y is set to 1.1 to keep the second line in the suptitle from hitting the top of the subplots. 

for idx, i in enumerate(true_vals): 
    ax_arr[idx].boxplot(data[:,idx], labels=i) 

f.savefig('suptitle_test.pdf', dpi=f.dpi, bbox_inches='tight',bbox_extra_artists=[my_suptitle])