ฝังกราฟ Matplotlib ใน PyQt Framework [ซ้ำกัน]

ฉันยังใหม่กับสแต็คโอเวอร์โฟลว์ นี่เป็นโพสต์ที่สองของฉัน ดังนั้นโปรดแก้ไขฉันหากฉันผิด จะแม่นยำและอธิบายปัญหาของฉัน ฉันกำลังพยายามฝังกราฟลงใน Qt Framework แต่ฉันทำได้เพียงแสดงกราฟทีละรายการในหน้าต่างแยกต่างหากเท่านั้น

รหัส UI:(dt.py)

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s
try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(431, 199)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.label = QtGui.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(20, 20, 71, 20))
        self.label.setObjectName(_fromUtf8("label"))
        self.X1 = QtGui.QLineEdit(self.centralwidget)
        self.X1.setGeometry(QtCore.QRect(20, 50, 71, 22))
        self.X1.setObjectName(_fromUtf8("X1"))
        self.label_3 = QtGui.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(350, 20, 46, 20))
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.Y1 = QtGui.QLineEdit(self.centralwidget)
        self.Y1.setGeometry(QtCore.QRect(180, 50, 71, 22))
        self.Y1.setObjectName(_fromUtf8("Y1"))
        self.Generate = QtGui.QPushButton(self.centralwidget)
        self.Generate.setGeometry(QtCore.QRect(160, 110, 101, 31))
        self.Generate.setObjectName(_fromUtf8("Generate"))
        self.label_2 = QtGui.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(180, 20, 71, 20))
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.R1 = QtGui.QLineEdit(self.centralwidget)
        self.R1.setGeometry(QtCore.QRect(330, 50, 71, 22))
        self.R1.setObjectName(_fromUtf8("R1"))
        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
        self.label.setText(_translate("MainWindow", "X-Co-ordinate", None))
        self.label_3.setText(_translate("MainWindow", "Radii", None))
        self.Generate.setText(_translate("MainWindow", "Generate", None))
        self.label_2.setText(_translate("MainWindow", "Y-Co-ordinate", None))

รหัสหลาม:

import os
import sys
import time
import matplotlib.pyplot as plt
import matplotlib.patches as patches
from PyQt4 import QtGui,QtCore

from dt import Ui_MainWindow

class demoMainClass(QtGui.QMainWindow,Ui_MainWindow):
    aX1 =  ("0")
    aY1 =  ("0")
    aR1 =  ("0")
    def __init__(self,parent=None):  
        super(demoMainClass,self).__init__()
        self.setupUi(self)
        self.demoWindowInitialize()
        self.demoFunction()
    def demoWindowInitialize(self):
        self.X1.insert(self.aX1)
        self.Y1.insert(self.aY1)
        self.R1.insert(self.aR1)
        self.Generate.clicked.connect(lambda: self.demoFunction())
    def demoFunction(self):
        x1=float(self.X1.text())
        y1=float(self.Y1.text())
        r1=float(self.R1.text())
        fig2 = plt.figure()
        ax2 = fig2.add_subplot(111, aspect='equal')
        ax2.add_patch(
            patches.Circle(
                (x1, y1),
                 r1,
                 fill=False
            )
        )
        plt.show()
        pass
if __name__ == "__main__":

    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = demoMainClass()
    ui.show()
    sys.exit(app.exec_())

ฉันต้องการฝังกราฟลงในหน้าต่าง QT ของฉันเอง พยายามด้วย QGraphicsView แต่ไม่ได้ผลลัพธ์ที่เหมาะสม


person Shubham Kuse    schedule 25.01.2018    source แหล่งที่มา
comment
มีตัวอย่างเพียงพอที่จะฝังพล็อต matplotlib ลงใน Qt GUI แม้แต่หน้า matplotlib ก็มีตัวอย่างอยู่ด้วย เพื่อเป็นการบันทึก อย่าแม้แต่จะนำเข้า pyplot เลย ซึ่งจะทำให้แน่ใจได้ว่าคุณจะไม่รู้สึกอยากใช้งานมัน   -  person ImportanceOfBeingErnest    schedule 25.01.2018
comment
ตกลง! ขอบคุณ จะผ่านรายการที่ซ้ำกัน   -  person Shubham Kuse    schedule 25.01.2018