• pyqtgraph逐点画波形图例子


    使用python的array模块创建能够动态改变大小的数组,结合numpy中的frombuffer函数转换为numpy的数组,最后在pyqtgraph中逐点画波形图。

     1 # -*- coding: utf-8 -*-#
     2 
     3 #-------------------------------------------------------------------------------
     4 # Name:         pyqtgraph逐点画波形图
     5 # Description:
     6 # Author:       lgk
     7 # Date:         2018/6/2
     8 #-------------------------------------------------------------------------------
     9 
    10 import pyqtgraph as pg
    11 import numpy as np
    12 import array
    13 
    14 app = pg.mkQApp()
    15 
    16 win = pg.GraphicsWindow()
    17 win.setWindowTitle(u'pyqtgraph逐点画波形图')
    18 win.resize(800, 500)
    19 
    20 data = array.array('d') #可动态改变数组的大小,double型数组
    21 historyLength = 200
    22 
    23 p = win.addPlot()
    24 p.showGrid(x=True, y=True)
    25 p.setRange(xRange=[0,historyLength], yRange=[-1.2, 1.2], padding=0)
    26 p.setLabel(axis='left', text='y / V')
    27 p.setLabel(axis='bottom', text='x / point')
    28 p.setTitle('y = sin(x)')
    29 
    30 curve = p.plot()
    31 idx = 0
    32 
    33 def plotData():
    34     global idx
    35     tmp = np.sin(np.pi / 50 * idx)
    36 
    37     if len(data)<historyLength:
    38         data.append(tmp)
    39     else:
    40         data[:-1] = data[1:]
    41         data[-1] = tmp
    42         # curve.setPos(idx-historyLength, 0)
    43         # p.enableAutoRange('x', True)
    44 
    45     curve.setData(np.frombuffer(data, dtype=np.double))
    46     # curve.setData(data) #也可以
    47     idx += 1
    48 
    49 timer = pg.QtCore.QTimer()
    50 timer.timeout.connect(plotData)
    51 timer.start(50)
    52 
    53 app.exec_()
  • 相关阅读:
    arcgis api for flex 开发入门
    Error #2148
    为Flex Builder设置测试服务器
    地图服务报 error #2035
    springMVC整理03--处理数据模型 & 试图解析器 & @ResponseBody & HttpEntity
    FastDFS安装与使用
    springMVC整理02--常用注解的使用
    springMVC整理01--搭建普通的工程
    Spring模块介绍
    spring05-Spring事务管理
  • 原文地址:https://www.cnblogs.com/luke0011/p/9128943.html
Copyright © 2020-2023  润新知