I'm wondering how to show a simple plot graph into a QtWidgets.QGraphicsView.
this is my code
from PyQt5 import QtCore, QtGui, QtWidgets
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
import numpy as np
import matplotlib.pyplot as plt
class Ui_scene(object):
def setupUi(self, scene):
scene.setObjectName("scene")
scene.resize(1109, 881)
self.graphicsView = QtWidgets.QGraphicsView(scene)
self.graphicsView.setGeometry(QtCore.QRect(30, 20, 461, 371))
self.graphicsView.setObjectName("graphicsView")
self.graphicsView_2 = QtWidgets.QGraphicsView(scene)
self.graphicsView_2.setGeometry(QtCore.QRect(30, 400, 461, 371))
self.graphicsView_2.setObjectName("graphicsView_2")
self.graphicsView_3 = QtWidgets.QGraphicsView(scene)
self.graphicsView_3.setGeometry(QtCore.QRect(520, 20, 461, 371))
self.graphicsView_3.setObjectName("graphicsView_3")
self.pushButton = QtWidgets.QPushButton(scene,clicked = lambda: self.graph1())
self.pushButton.setGeometry(QtCore.QRect(720, 570, 75, 23))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(scene)
QtCore.QMetaObject.connectSlotsByName(scene)
def graph1(self):
figure=Figure()
axes=figure.gca()
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
axes.set_title("title")
axes.plot(t,s)
canvas = FigureCanvas(figure)
canvas.setGeometry(0, 0, 500, 500)
print("graph1")
self.graphicsView.setScene()
def retranslateUi(self, scene):
_translate = QtCore.QCoreApplication.translate
scene.setWindowTitle(_translate("scene", "Form"))
self.pushButton.setText(_translate("scene", "PushButton"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
scene = QtWidgets.QWidget()
ui = Ui_scene()
ui.setupUi(scene)
scene.show()
sys.exit(app.exec_())
As you can see, I create three graph viewers and the idea is to display a plot on each graph. the problem is I couldn't link the Qtwidgets and the figure.
I'm working with qt 5.9.7 and pyqtgraph is not supported with this version. I tried harder to update to qt 5.12 but I didn't succeed.