ich habe eine GUI erstellt, welche Live-Daten plotten soll und so sieht sie aus:
Das plotten an sich funktioniert, nur leider habe ich einige Schwierigkeiten mit der Darstellung. Ich bekomme es nicht hin, dass der Plot richtig in das Layout skaliert wird, in welches er hinzugefügt wird.
undFigure(figsize = (w,h))
habe ich schon probiert, allerdings ohne Erfolg..plt.tight_layout()
Hier ist der Code welcher von
aus der GUI generiert wurde:pyuic5
Code: Alles auswählen
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_GTM_Form(object):
def setupUi(self, GTM_Form):
GTM_Form.setObjectName("GTM_Form")
GTM_Form.resize(869, 662)
GTM_Form.setAutoFillBackground(False)
GTM_Form.setStyleSheet("background-color: rgb(62,62,62)")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(GTM_Form)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.tabWidget = QtWidgets.QTabWidget(GTM_Form)
font = QtGui.QFont()
font.setPointSize(20)
font.setKerning(True)
self.tabWidget.setFont(font)
self.tabWidget.setLayoutDirection(QtCore.Qt.LeftToRight)
self.tabWidget.setStyleSheet("color: white;")
self.tabWidget.setLocale(QtCore.QLocale(QtCore.QLocale.German, QtCore.QLocale.Germany))
self.tabWidget.setObjectName("tabWidget")
self.tabAusrichtung = QtWidgets.QWidget()
self.tabAusrichtung.setObjectName("tabAusrichtung")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.tabAusrichtung)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.horizontalLayoutTabAusrichtung = QtWidgets.QHBoxLayout()
self.horizontalLayoutTabAusrichtung.setObjectName("horizontalLayoutTabAusrichtung")
self.PicLabel = QtWidgets.QLabel(self.tabAusrichtung)
self.PicLabel.setText("")
self.PicLabel.setObjectName("PicLabel")
self.horizontalLayoutTabAusrichtung.addWidget(self.PicLabel)
self.horizontalLayout_4.addLayout(self.horizontalLayoutTabAusrichtung)
self.tabWidget.addTab(self.tabAusrichtung, "")
self.tabPlot1 = QtWidgets.QWidget()
self.tabPlot1.setObjectName("tabPlot1")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.tabPlot1)
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.horizontalLayoutTabPlot1 = QtWidgets.QHBoxLayout()
self.horizontalLayoutTabPlot1.setObjectName("horizontalLayoutTabPlot1")
self.horizontalLayout_5.addLayout(self.horizontalLayoutTabPlot1)
self.tabWidget.addTab(self.tabPlot1, "")
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.tab)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.TestLabel = QtWidgets.QLabel(self.tab)
self.TestLabel.setText("")
self.TestLabel.setObjectName("TestLabel")
self.horizontalLayout_3.addWidget(self.TestLabel)
self.verticalLayout_2.addLayout(self.horizontalLayout_3)
self.tabWidget.addTab(self.tab, "")
self.horizontalLayout.addWidget(self.tabWidget)
self.horizontalLayout_2.addLayout(self.horizontalLayout)
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.BtnStart = QtWidgets.QPushButton(GTM_Form)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.BtnStart.sizePolicy().hasHeightForWidth())
self.BtnStart.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setPointSize(20)
self.BtnStart.setFont(font)
self.BtnStart.setStyleSheet("background-color: rgb(50,50,50);\n"
"color: white;")
self.BtnStart.setObjectName("BtnStart")
self.verticalLayout.addWidget(self.BtnStart)
self.BtnEnd = QtWidgets.QPushButton(GTM_Form)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.BtnEnd.sizePolicy().hasHeightForWidth())
self.BtnEnd.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setPointSize(20)
self.BtnEnd.setFont(font)
self.BtnEnd.setStyleSheet("background-color: rgb(50,50,50);\n"
"color: white;")
self.BtnEnd.setObjectName("BtnEnd")
self.verticalLayout.addWidget(self.BtnEnd)
self.BtnShutdown = QtWidgets.QPushButton(GTM_Form)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.BtnShutdown.sizePolicy().hasHeightForWidth())
self.BtnShutdown.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setPointSize(20)
self.BtnShutdown.setFont(font)
self.BtnShutdown.setStyleSheet("background-color: rgb(50,50,50);\n"
"color: white;")
self.BtnShutdown.setObjectName("BtnShutdown")
self.verticalLayout.addWidget(self.BtnShutdown)
self.horizontalLayout_2.addLayout(self.verticalLayout)
self.retranslateUi(GTM_Form)
self.tabWidget.setCurrentIndex(1)
QtCore.QMetaObject.connectSlotsByName(GTM_Form)
def retranslateUi(self, GTM_Form):
_translate = QtCore.QCoreApplication.translate
GTM_Form.setWindowTitle(_translate("GTM_Form", "GTM"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tabAusrichtung), _translate("GTM_Form", "Ausrichtung"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tabTransmission), _translate("GTM_Form", "Transmission"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("GTM_Form", "Page"))
self.BtnStart.setText(_translate("GTM_Form", "Start"))
self.BtnEnd.setText(_translate("GTM_Form", "End"))
self.BtnShutdown.setText(_translate("GTM_Form", "Shutdown"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
GTM_Form = QtWidgets.QWidget()
ui = Ui_GTM_Form()
ui.setupUi(GTM_Form)
GTM_Form.show()
sys.exit(app.exec_())
Code: Alles auswählen
import matplotlib.pyplot as plt
from PyQt5 import QtGui, QtWidgets, QtCore, uic
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtWidgets import *
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
class myUi(QtWidgets.QWidget):
def __init__(self):
super(myUi, self).__init__()
uic.loadUi("test3.ui", self)
self.show()#Maximized()
self.Btn()
def Btn(self):
self.BtnStart.clicked.connect(self.StartGTM)
self.BtnEnd.clicked.connect(self.EndGTM)
self.BtnShutdown.clicked.connect(self.ShutdownGTM)
def StartGTM(self):
print("start")
ui.setupPlot()
def EndGTM(self):
print("end")
def ShutdownGTM(self):
print("shutdown")
exit()
def setupPlot(self):
self.fig = plt.figure()
while (1):
self.fig.clear()
plt.ylim(0,110)
bar_width = 50
plt.xticks(xticks)
plt.bar(xticks, transm_values, bar_width, color="#CC0000")
plt.xlabel('Daten')
plt.ylabel('Prozent')
self.canvas = FigureCanvas(self.fig)
self.widget = QtWidgets.QWidget()
clearLayout(self.horizontalLayoutTabTransmission)
self.horizontalLayoutTabTransmission.addWidget(self.canvas)
self.horizontalLayoutTabTransmission.addWidget(self.widget)
plt.draw()
def clearLayout(layout):
while layout.count():
child = layout.takeAt(0)
if child.widget() is not None:
child.widget().deleteLater()
elif child.layout() is not None:
clearLayout(child.layout())
Danke schon mal im Voraus!