我试图在python中使用matplotlib.pyplot绘制图形,然后将它们保存在单个pdf文件的不同页面中。但是我收到此错误
AttributeError: 'NoneType' object has no attribute 'endStream'
我尝试过
from matplotlib.backends.backend_pdf import PdfPages as P
with P("ML_Data/DB_Scan_bin_%s_outlier.pdf"%(flag)) as pdf:
plt.figure()
plt.clf()
if(k>=0):
plt.plot(xy_x.iloc[0][0], xy_y.iloc[0][0],'.',c=tuple(col),alpha=0.9,label='Group = %s, No. of Core Candidates = %s, No. of Outliers = %s'%(count,np.shape(xy_x)[0],np.shape(xy_xout)[0]))
else :
plt.plot(xy_x.iloc[0][0], xy_y.iloc[0][0],'.',c=tuple(col),alpha=0.9,label='All of Outliers = %s'%(np.shape(xy_xout)[0]))
plt.legend()
for i in range(1,len(xy_x)+1):
plt.plot(xy_x.iloc[i-1], xy_y.iloc[i-1],c=tuple(col),alpha=0.9)
for i in range(1,len(xy_xout)+1):
plt.plot(xy_xout.iloc[i-1], xy_yout.iloc[i-1],c='black',alpha=0.5)
#fig = plt.gcf()
pdf.savefig(plt.gcf())
pdf.close()