Hi everyone. I'm new in PyQt and pyqtgraph.
I'm trying to embed my pyqtgraph animation inside a GUI application made
with Qt Designer.
*I have this code for the animation: *
import numpy as np
import scipy as sp
from scipy import signal
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
win = pg.GraphicsWindow()
win.setWindowTitle(' Scrolling ECG')
#---------------------------------------------------------------
Fs = 400 #frecuencia de muestreo
Ts = 1/Fs #tiempo de muestreo
BMP = 72 #latidos por minuto
PeriodoLat = 60/BMP #duracion de un latido cardiaco
duracion = 20 #duracion de la señal ECG completa en segundos
#tiempos de constantes
Pint = 0.132*PeriodoLat
PRint = 0.204*PeriodoLat
STseg = 0.12*PeriodoLat
QTint = 0.48*PeriodoLat
q1 = PRint+0.018*PeriodoLat
r1 = PRint+0.06*PeriodoLat
r2 = PRint+0.095*PeriodoLat
s = PRint+0.11*PeriodoLat
QRSint = s-q1
st = PRint+QRSint+STseg
t2 = st+0.25*PeriodoLat
#constantes de amplitud
rPeak = 1
pPeak = 0.13
qPeak = 0.26
sPeak = 0.35
tPeak = 0.1875
#constantes de líneas QRS
#y = mx+c
#m = (y2-y1)/(x2-x1)
#c = y1-m*x1
mq = -qPeak/(q1-PRint)
cq = -mq*PRint
mrUp = (rPeak+qPeak)/(r1-q1)
crUp = rPeak-mrUp*r1
mrDown = (-sPeak-rPeak)/(r2-r1)
crDown = rPeak-mrDown*r1
ms = sPeak/(s-r2)
cs = -ms*s
#Generacion de onda P
tP = np.arange(0, Pint, Ts)
P = pPeak*sp.sin(tP * sp.pi/Pint)
#Generacion del segmento PR
tPR = np.arange(Pint, PRint, Ts)
PRseg = np.zeros(len(tPR))
#Generacion del complejo QRS
tQ = np.arange(PRint, q1, Ts)
Q = mq*tQ + cq
tR = np.arange(q1, r1, Ts)
R = mrUp*tR + crUp
tR2 = np.arange(r1, r2, Ts)
R2 = mrDown*tR2 + crDown
ts = np.arange(r2, s, Ts)
S = ms*ts + cs
#Genenracion del segmento ST
tST = np.arange(s, st, Ts)
STseg = np.zeros(len(tST))
#Generacion de la onda T
tT = np.arange(st, t2, Ts)
T = tPeak*sp.sin((tT-st)*sp.pi/(t2-st));
#Genenracion del segmento TP
tTP = np.arange(t2, PeriodoLat, Ts)
TPseg = np.zeros(len(tTP))
ecg = np.concatenate((P, PRseg, Q, R, R2, S, STseg, T, TPseg))
tecg = Ts*np.arange(0, len(ecg))
M = len(ecg) #tamanio de un pulso ecg
n = int(np.ceil((duracion*M)/PeriodoLat)) #tamanio total de la senial
alfa = 1
B = [0.1*10**1]
A = np.concatenate((1, np.zeros(M-1), -alfa), axis=None)
xzeropad = np.concatenate((ecg, np.zeros(n-M)), axis=None)
ecgPer = sp.signal.lfilter(B, A, xzeropad)
t = Ts*np.arange(0, len(xzeropad))
# ADICION DE RUIDO A LA SEÑAL ECG
WN = 0.005*np.random.randn(len(ecgPer)) #Ruido blanco
EN_N = 0.005*sp.sin(2*sp.pi*60*t); #Ruido de la red electrica
ECG_N = ecgPer + EN_N + WN
#DISENIO DEL FILTRO
fc = 36 #frecuencia de corte
fnorm = fc /(Fs/2) #frecuencia normalizada
b,a= sp.signal.butter(3, fnorm, 'low')
ecgFilt = sp.signal.lfilter(b, a, ECG_N)
#pg.plot (t, ecgFilt)
#---------------------------------------------------------------------
p1 = win.addPlot(title="ECG ANIMATED")
p1.setXRange (0, 3)
p1.setYRange (-0.4, 0.92)
curve1 = p1.plot(t, ecgFilt)
ptr1 = 0
def update1():
global ecgFilt, curve1, ptr1, t
ecgFilt[:-1] = ecgFilt[1:] # shift data in the array one sample left
# (see also: np.roll)
curve1.setData(t, ecgFilt)
ptr1 += 1
#update plot
def update():
update1()
timer = pg.QtCore.QTimer()
timer.timeout.connect(update)
timer.start(10)
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
*And I want to embed the pyqtgraph plot in this code:*
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(700, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(280, 40, 31, 31))
self.label_2.setObjectName("label_2")
self.BotonSimular = QtWidgets.QPushButton(self.centralwidget)
self.BotonSimular.setGeometry(QtCore.QRect(360, 30, 131, 41))
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.BotonSimular.setFont(font)
self.BotonSimular.setStyleSheet("background-color: rgb(85, 255,
0);")
self.BotonSimular.setObjectName("BotonSimular")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(190, 100, 321, 41))
self.label_3.setObjectName("label_3")
self.BotonReset = QtWidgets.QPushButton(self.centralwidget)
self.BotonReset.setGeometry(QtCore.QRect(530, 30, 131, 41))
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.BotonReset.setFont(font)
self.BotonReset.setStyleSheet("background-color: rgb(255, 0, 0);")
self.BotonReset.setObjectName("BotonReset")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(20, 30, 141, 41))
self.label.setObjectName("label")
self.InBMP = QtWidgets.QLineEdit(self.centralwidget)
self.InBMP.setGeometry(QtCore.QRect(180, 40, 71, 31))
self.InBMP.setStyleSheet("background-color: rgb(255, 255, 255);")
self.InBMP.setObjectName("InBMP")
self.Plot = PlotWidget(self.centralwidget)
self.Plot.setGeometry(QtCore.QRect(40, 200, 611, 281))
self.Plot.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.Plot.setFrameShadow(QtWidgets.QFrame.Raised)
self.Plot.setObjectName("Plot")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "ecgTrain"))
self.label_2.setText(_translate("MainWindow",
"<html><head/><body><p><span style=\" font-size:10pt;
font-weight:600;\">BMP</span></p></body></html>"))
self.BotonSimular.setText(_translate("MainWindow", "SIMULAR"))
self.label_3.setText(_translate("MainWindow",
"<html><head/><body><p align=\"center\"><span style=\" font-size:12pt;
font-weight:600;\">ELECTROCARDIOGRAMA</span></p></body></html>"))
self.BotonReset.setText(_translate("MainWindow", "RESET"))
self.label.setText(_translate("MainWindow",
"<html><head/><body><p><span style=\" font-size:10pt;
font-weight:600;\">Frecuencia Cardiaca</span></p></body></html>"))
from pyqtgraph import PlotWidget
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
*This is the application that I try to embed the animation*
[image: Capture.PNG]
If somebody have an idea
Thanks
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/6413c165-0aec-4562-9215-6d3497380e6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.