Bha*_*mar 6 python matplotlib pdfpages
我有一个报告要自动提交,我使用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()
Run Code Online (Sandbox Code Playgroud)
您应该能够在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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1899 次 |
| 最近记录: |