matplotlib 그림을 Qt Designer에서 만든 양식에 연결하는 가장 좋은 방법을 모르겠습니다. 나는 QtDesigner에서 만든 다음 pyuic5를 통해 python으로 컴파일 된 양식을 가지고 있습니다. 내 주요 프로그램은 다음과 같습니다Qt 디자이너 폼과 PyQt5를 사용하여 QWidget 내부에 matplotlib 그림 그리기
을 myApp 다음 pyuic5 (design.py)에 의해 변환 된 Qt 디자이너에서 만든 app_framework.py 양식 호출import app_framework as af
import matplotlib
from PyQt5 import QtWidgets
import sys
matplotlib.use('Qt5Agg')
app = QtWidgets.QApplication(sys.argv)
form = af.MyApp()
form.show()
app.exec_()
: 나는 어디에서 이것으로 혼란 스러워요
from PyQt5.QtWidgets import QApplication, QMainWindow
import design
class MyApp(QMainWindow, design.Ui_mainWindow):
def __init(self):
super(self.__class__, self).__init__()
<button initializations>
<function definitions for button callbacks>
을 framework QtDesigner의 미리 준비된 빈 위젯이나 그 종류의 뭔가에 matplotlib 그림을 연결하여 상황에 따라 GUI 창에 새 데이터를 플롯 할 수 있습니다 (텍스트 입력, 버튼 누름 등)
어떤 스레드가 SO과에 있습니다.하지만, Qt Designer 폼에서이 위젯을위한 공간을 만들고 플롯을 연결하거나 위젯을 작성한 다음 링크 및 플로팅하는 올바른 프로세스를 이해하고 있는지 잘 모르겠습니다. 로 app_framework.py 다음
from PyQt5 import QtCore, QtGui, QtWidgets
# **** ADDED THIS
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as Canvas
# ****
class Ui_mainWindow(object):
def setupUi(self, mainWindow):
<mainWindow setup stuff>
self.centralwidget = QtWidgets.QWidget(mainWindow)
# ****ALTERED THIS FROM self.plotWidget = QtWidgets.QWidget(self.centralWidget)
self.plotWidget = MplWidget(self.centralWidget)
# *****
self.plotWidget.setGeometry(QtCore.QRect(20, 250, 821, 591))
self.plotWidget.setObjectName("plotWidget")
# **** ADDED THIS
class MplCanvas(Canvas):
def __init__(self):
self.fig = Figure()
self.ax = self.fig.add_subplot(111)
Canvas.__init__(self, self.fig)
Canvas.setSizePolicy(self, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
Canvas.updateGeometry(self)
class MplWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.canvas = MplCanvas()
# ***********
과 : 지금까지 IS Qt는 창조주 내부 빈는 QWidget을 생성 한 적이 후 다음과 같이 pyuic5 컴파일 후, 나는 design.py 파일을 변경 무엇
from PyQt5.QtWidgets import QApplication, QMainWindow
import design
class MyApp(QMainWindow, design.Ui_mainWindow):
def __init(self):
super(self.__class__, self).__init__()
self.setupUi(self)
self.pushButton_plotData.clicked.connect(self.plot_data)
def plot_data(self):
x=range(0, 10)
y=range(0, 20, 2)
self.plotWidget.canvas.ax.plot(x, y)
self.plotWidget.canvas.draw()
플롯 푸시 버튼을 클릭해도 아무 효과가 없을 것이라고 생각했습니다. 그것은 자물쇠를 열지 않으며, 단지 아무것도 그릴하지 않습니다. 필자는이 빈 위젯에 matplotlib 그림 및/또는 캔버스를 그릴 때 기본적으로 중요한 것을 놓치고 있다고 생각합니다.