PYQT5保存图像并将其加载到QGraphicsView

时间:2019-12-12 05:14:22

标签: python pyqt5

我正在尝试保存图像并将其加载到界面中的QGraphics视图中。保存的图像以低分辨率保存在png文件中,并且该图像在界面的QGraphicsView上不显示。

x = data.drop('DrainStatnumout',axis='columns')
y = data['DrainStatnumout'] 
le_F = LabelEncoder()
le_Assembly1_Availability = LabelEncoder()
le_Assembly2_Availability = LabelEncoder()
le_LaserCutting_Availability = LabelEncoder()
data['Failuer_n'] = le_F.fit_transform(data['Failuer'])
data['Assembly1_Availability_n'] = le_Assembly1_Availability.fit_transform(data['Assembly1_Availability'])
data['Assembly2_Availability_n'] = le_Assembly2_Availability.fit_transform(data['Assembly2_Availability'])
data['LaserCutting_Availability_n'] = le_LaserCutting_Availability.fit_transform(data['LaserCutting_Availability'])
xx = data.drop(['Assembly1_Availability','Assembly2_Availability',
                'LaserCutting_Availability','Failuer','DrainStatnumout'],axis='columns')
X=pd.DataFrame(xx)
Y=pd.DataFrame(y)
X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.20)
seed=7

#prepare model

models =[]
models.append(('LR',LogisticRegression(solver='lbfgs')))
models.append(('LDA',LinearDiscriminantAnalysis()))
models.append(('KNN',KNeighborsClassifier()))
models.append(('CART',DecisionTreeClassifier()))
models.append(('NB',GaussianNB()))
models.append(('SVM',SVC()))

#evaluate each model in turn

results=[]
names=[]
scoring='accuracy'
for name,model in models:
    kfold=model_selection.KFold(n_splits=10, random_state=seed)
    cv_results=model_selection.cross_val_score(model,X,Y,cv=kfold,scoring=scoring)
    results.append(cv_results)
    names.append(name)
    msg="%s:%f(%f)"%(name,cv_results.mean(),cv_results.std())
    fig=plt.figure()
    fig.suptitle('Algoriithm Comparison')
    ax=fig.add_subplot(111)
    plt.boxplot(results)
    ax.set_xticklabels(names)
    plt.show()
     #self.plt.savefig('f1.png')



    app = QtGui.QApplication(sys.argv)
    view = QtGui.QGraphicsView()
    scene = QtGui.QGraphicsScene()
    view.setScene(scene)
    scene.addPixmap(QtGui.QPixmap("fig1.png"))
    view.scale(0.8, 0.75)
    view.show()

    pixmap = QtGui.QPixmap(view.viewport().size())
    view.viewport().render(pixmap)
    pixmap.save("test.png")

0 个答案:

没有答案