gpt4 book ai didi

Matplotlib 不保存字幕

转载 作者:行者123 更新时间:2023-12-05 00:49:57 26 4
gpt4 key购买 nike

使用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)

最佳答案

Using the advice given here ,

将以下内容添加到 savefig 命令将产生一个紧凑的绘图,并在保存的图形中保留字幕:

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

关于Matplotlib 不保存字幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33414819/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com