Matplotlib无法保存suptitle。

3
使用matplotlib 1.4.3版本和以下代码,在显示图形和总标题方面没有问题,但保存时总标题会被删除。
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)
1个回答

10

使用此处给出的建议,

将以下内容添加到 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])

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接