有一个名为scikitplot
的包,其中包含一些对我的应用程序非常有用的工具。它可以通过调用单个函数自动绘制一些特定的图形。问题是我需要在PyQt窗口中嵌入这些绘图。我知道在使用PyQt后端处理matplotlib
it is possible to do this时。但是,在这种情况下,我不知道如何继续,因为scikitplot
函数每个函数都返回一个plot,我也不知道如何将现有plot添加到figure小部件中。你知道吗
代码应该是这样的(显然不起作用,但我希望它能帮助解释我的问题):
import sys
from PyQt5 import QtWidgets
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
import scikitplot as skplt
from sklearn.naive_bayes import GaussianNB
class ExampleWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self._main = QtWidgets.QWidget()
self.setCentralWidget(self._main)
## Lines to make minimal example
X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33)
nb = GaussianNB()
nb.fit(X_train, y_train)
predicted_probas = nb.predict_proba(X_test)
## The plots I want to show in the window
## It doesn't work because they aren't widgets, but I hope you get the idea
plot1 = skplt.metrics.plot_cumulative_gain(y_test, predicted_probas)
plot2 = skplt.metrics.plot_roc(y_test, predicted_probas)
layout = QtWidgets.QHBoxLayout()
layout.addWidget(plot1)
layout.addWidget(plot2)
self.setLayout(layout)
self.showMaximized()
if __name__ == '__main__':
app = QtWidgets.QApplication([])
ex = ExampleWindow()
ex.show()
sys.exit(app.exec_())
您需要在应用程序中创建轴并将其传递给plotting函数。你知道吗
第二个情节也一样。你知道吗
请注意,这是从我的头顶写的,没有测试,因为我没有可用的
scikitplot
。你知道吗相关问题 更多 >
编程相关推荐