Created
March 31, 2022 04:54
-
-
Save allrobot/c2544b5de7afdbbbfc89c9d476fc5b6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ble | |
from pyqtgraph import PlotWidget | |
import pyqtgraph as pg | |
import numpy as np | |
from PyQt5 import QtCore | |
class Plot_Show(object): | |
''' | |
绘图组件,输出5~550范围的数值 | |
定义绘图时的参数:QWidget、组件y作标、组件x作标、y轴数据、组件宽高、组件对象文本 | |
Form,y,x,data,length = 1800, width = 250, high = 120, text = "sEMG Voltage" | |
''' | |
def __init__(self,Form,y,x,data,text=""): | |
# length = 1800, width = 250, high = 120, text = "sEMG Voltage" | |
self.Form=Form | |
self.y=y | |
self.x=x | |
self.data=ble.EMG[data] | |
self.length=1800 | |
if(text==""): | |
self.test="sEMG Voltage" | |
else: | |
self.text = text | |
self.graphicsView = PlotWidget(self.Form) | |
self.initUI() | |
def initUI(self): | |
self.graphicsView.setGeometry(QtCore.QRect(self.y, self.x, 250, 120)) | |
self.graphicsView.hideButtons() | |
self.graphicsView.setObjectName(self.text) | |
self.graphicsView.setLabel(axis="left",text=self.text) | |
self.graphicsView.setLabel(axis='bottom',text='Time') | |
self.graphicsView.setMouseEnabled(x=False,y=False) | |
self.graphicsView.setAntialiasing(True) | |
self.graphicsView.setMenuEnabled(False) | |
self.graphicsView.hideButtons() | |
self.data1 = np.zeros(self.length) | |
self.curve1 = self.graphicsView.plot(self.data1) | |
self.ptr1 = 0 | |
def update1(): | |
global data1, ptr1 | |
self.graphicsView.setRange(xRange=[self.ptr1,self.ptr1+self.length],yRange=[5,550],padding=0) | |
self.data1[:-1] = self.data1[1:] # shift data in the array one sample left | |
self.data1[-1] = self.data | |
self.ptr1 += 1 | |
self.curve1.setData(self.data1) | |
self.curve1.setPos(self.ptr1, 0) | |
self.timer = pg.QtCore.QTimer() | |
self.timer.timeout.connect(update1) | |
self.timer.start(10) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment