我正在尝试将多个图形绘制到一个PDF上,但它会生成损坏的PDF。
import sys, os, pandas as pd, numpy as np, matplotlib.pyplot as plt
import pylab, scipy.stats as stats, calendar
from matplotlib.backends.backend_pdf import PdfPages
def plotLineGraph(df):
fig = plt.figure()
ax = fig.add_subplot(211)
df.plot(ax=ax)
ax = plt.subplot(111)
return fig
pp = PdfPages(r'C:\myPLOT.pdf')
for ii in [1,2,3,4]:
df = pd.DataFrame({'x': np.rand(500), 'y':np.rand(500)})
pp.savefig(plotGraph(df))
pp.close()
如何修改上面的代码,以便在一个PDF文件中成功获取4个图。