将绘制曲线的 pyplot 添加到 QGraphicsView 时出错

Error adding the pyplot of plotted curve to QGraphicsView

我是新手,想知道在使用 Pyuic 转换的 py 文件时尝试添加绘图时出了什么问题。 我试着按照这个网页的答案,但我似乎犯了一个错误。 Put a Matplotlib plot as a QGraphicsItem/into a QGraphicsView

错误

Traceback (most recent call last):
  File "C:\Users\Administrator\PycharmProjects\Request_Project\Non_real_time_recognition.py", line 155, in <module>
    ui.setupUi(form)
  File "C:\Users\Administrator\PycharmProjects\Request_Project\Non_real_time_recognition.py", line 87, in setupUi
    proxy_widget=self.scene.addWidget(canvas)
TypeError: addWidget(self, QWidget, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type 'FigureCanvasTemplate'

代码:

import h5py
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets
import scipy.io as scio
from PyQt5.QtCore import QSize
from PyQt5.QtWidgets import QGraphicsScene, QGraphicsPixmapItem
from matplotlib.backends.backend_template import FigureCanvas
from PyQt5.QtGui import QPainter, QPixmap, QWheelEvent
from matplotlib.figure import Figure
class UiForm(object):
    def __init__(self):
        E1 = scio.loadmat('S1_E1_A1.mat')
        # display emg data,shape:[2292526,16]
        self.E1_emg = E1['emg']
        self.E1_label = E1['restimulus']
    def setupUi(self,Form):
        Form.setObjectName("Form")
        Form.resize(550, 419)
        Form.setFixedSize(Form.width(), Form.height())
        # plt.plot(self.E1_emg[0:200000] * 20000)
        # plt.plot(self.E1_label[0:200000]*100)

        self.Plotting = QtWidgets.QGraphicsView(Form)
        self.Plotting.setGeometry(QtCore.QRect(10, 10, 361, 171))
        self.Plotting.setObjectName("Plotting")
        self.scene=QtWidgets.QGraphicsScene()

        figure=Figure()
        axes=figure.gca()
        axes.set_title("sEMG")
        x=np.linspace(0,200000,num=200000)
        y=self.E1_emg[0:200000] * 20000
        axes.plot(x,y,"-k",label="sEMG")
        axes.legend()
        axes.grid(True)

        canvas=FigureCanvas(figure)

        proxy_widget=self.scene.addWidget(canvas)
        self.Plotting.setScene(proxy_widget)

        self.Image = QtWidgets.QGraphicsView(Form)
        self.Image.setGeometry(QtCore.QRect(390, 10, 151, 171))
        self.Image.setObjectName("Image")
        .....

期待图片

Excpect1

Excpect2

问题已解决

我导入 from matplotlib.backends.backend_template import FigureCanvas,现在导入 from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas

self.Plotting.setScene(proxy_widget)self.Plotting.setScene(self.scene)