我有一份要自动提交的报告,我正在使用 matplotlib 来执行此操作。但是我无法弄清楚如何在中间的标题开头创建一个空白页面,以了解所执行的分析类型
with PdfPages('review_count.pdf') as pdf:
for cat in self.cat_vars.keys():
if len(self.cat_vars[cat]) > 1:
plt.figure()
self.cat_vars[cat].plot(kind='bar')
plt.title(cat)
# saves the current figure into a pdf page
pdf.savefig()
plt.close()
最佳答案
您应该能够在带有标题的 for
循环之前创建一个图形。您还需要关闭轴框架 (plt.axis('off')
)。
with PdfPages('review_count.pdf') as pdf:
plt.figure()
plt.axis('off')
plt.text(0.5,0.5,"my title",ha='center',va='center')
pdf.savefig()
plt.close()
for cat in self.cat_vars.keys():
if len(self.cat_vars[cat]) > 1:
plt.figure()
self.cat_vars[cat].plot(kind='bar')
plt.title(cat)
# saves the current figure into a pdf page
pdf.savefig()
plt.close()
关于python - 如何为使用 matplotlib 创建的 PDF 文档创建标题页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32348443/