PDF页“AttributeError:'NoneType'对象没有属性'endStream'”

2024-04-26 23:43:54 发布

您现在位置: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()

Tags: 文件ofalphapdfplotmatplotlibasnp