我正在尝试将我的输出(70 多张图表)从 jyputer 笔记本保存到 pdf 文件中。没有错误或任何错误,但只有第一个图表被导出。谁能帮我理解什么是错的?
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.backends.backend_pdf
pdf = matplotlib.backends.backend_pdf.PdfPages("output.pdf")
df_num = df.select_dtypes(include = ['float64', 'int64'])
with PdfPages(r'output.pdf') as export_pdf:
fig = plt.figure(figsize=(12,12))
for col in df_num.columns:
hist = df_num[col].hist(bins=10)
print("Plotting for column {}".format(col))
plt.title("{}".format(col), fontsize=20)
plt.show()
export_pdf.savefig(fig)