错误,将绘制曲线的Pyplot添加到QgraphicsView
我对此很陌生,想知道在使用 Pyuic 转换的 py 文件时尝试添加绘图时出了什么问题。 我试图遵循该网页的答案,但我似乎犯了一个错误。 将 Matplotlib 绘图作为 QGraphicsItem/放入 QGraphicsView< /a>
错误
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")
.....
图片除外
I am new to this and wonder what went wrong when trying to add plot when using Pyuic converted py files.
I tried to follow the answer of this web page, but I seem to have made a mistake.
Put a Matplotlib plot as a QGraphicsItem/into a QGraphicsView
ERROR
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'
Code:
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")
.....
Excpect Picture
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题解决了。
我导入
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)
The problem is solved.
I import
from matplotlib.backends.backend_template import FigureCanvas
, now importfrom matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
.self.Plotting.setScene(proxy_widget)
toself.Plotting.setScene(self.scene)