最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PyQt5使用pyqtgraph繪制波形圖

 更新時(shí)間:2023年01月13日 16:24:02   作者:SongYuLong的博客  
pyqtgraph是Python平臺(tái)上一種功能強(qiáng)大的2D/3D繪圖庫,相當(dāng)于matplotlib庫,比它更強(qiáng)大。本文就來利用pyqtgraph實(shí)現(xiàn)繪制波形圖,需要的可以參考一下

主程序代碼

import sys
import numpy as np
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *

import pyqtgraph as pg

from ui_demo02 import Ui_MainWindow


class GraphDemowWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(GraphDemowWindow, self).__init__(parent)
        self.setupUi(self)

        pg.setConfigOptions(antialias=True) # 設(shè)置開啟抗鋸齒

        self.drawGraphicsLayoutWidget()
        self.drawPoltWidget()

    # 在QWidget控件提升為pyqtgraph.GraphicsLayoutWidget類型的控件上畫波形
    def drawGraphicsLayoutWidget(self):
        # pyqtgraph.GraphicsLayoutWidget 支持的方法有:
        # ['nextRow', 'nextCol', 'nextColumn', 'addPlot', 'addViewBox', 'addItem', 'getItem', 'addLayout', 'addLabel', 'removeItem', 'itemIndex', 'clear']
        self.graphicsLayout.clear() # 清除
        plt1 = self.graphicsLayout.addPlot(y=np.random.normal(size=1000), title="溫度")
        plt2 = self.graphicsLayout.addPlot(y=np.random.normal(size=500), title="濕度")
        self.graphicsLayout.nextRow() # 圖像坐標(biāo)換行
        plt3 = self.graphicsLayout.addPlot(y=np.random.normal(size=800), title="光照度")
        plt4 = self.graphicsLayout.addPlot(y=np.random.normal(size=800), title="紫外線強(qiáng)度")


    # 在QWidget控件提升為pyqtgraph.PlotWidget類型的控件上畫波形
    def drawPoltWidget(self):
        # pyqtgraph.PlotWidget 支持的方法有:
        # ['addItem', 'removeItem', 'autoRange', 'clear', 'setAxisItems', 'setXRange', 
        #           'setYRange', 'setRange', 'setAspectLocked', 'setMouseEnabled', 
        #           'setXLink', 'setYLink', 'enableAutoRange', 'disableAutoRange', 
        #           'setLimits', 'register', 'unregister', 'viewRect']
        

        # pen = pg.mkPen(255, 0, 0)
        # pen = pg.mkPen("#ff0000")
        # pen = pg.mkPen(color='r', width=3)
        pen = pg.mkPen({'color':'0F0', 'width':1})
        plt1 = self.graphPlot.plot(np.random.normal(size=100), pen=pen,  symbolBrush=(255, 0, 0), symbolPen=(0, 255, 0))

        pen2 = pg.mkPen(color="F00", width=1)
        plt2 = self.graphPlot.plot(np.random.normal(size=50), pen=pen2,  symbolBrush=(0, 255, 0), symbolPen=(255, 0, 0))

        self.graphPlot.setAntialiasing(True)
        self.graphPlot.setBackground("#ffffff")
        
        


if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = GraphDemowWindow()
    win.show()
    sys.exit(app.exec_())

UI界面設(shè)計(jì)

包含了兩個(gè)QWidget控件也可以是QGraphicsView控件類型。

兩個(gè)控件分別提升為pyqtgraph.GraphicsLayoutWidget類型和pyqtgraph.PlotWidget

GraphicsLayoutWidget類型通過addPlot方法添加波形數(shù)據(jù),每個(gè)波形都占有獨(dú)立的區(qū)域。

plt1 = self.graphicsLayout.addPlot(y=np.random.normal(size=1000), title=“溫度”)
plt2 = self.graphicsLayout.addPlot(y=np.random.normal(size=500), title=“濕度”)

PlotWidget類型通過plot方法添加波形數(shù)據(jù),同一控件內(nèi)多個(gè)plot占用同一窗口區(qū)域。

pen2 = pg.mkPen(color=“F00”, width=1)
plt2 = self.graphPlot.plot(np.random.normal(size=50), pen=pen2, symbolBrush=(0, 255, 0), symbolPen=(255, 0, 0))

控件提升

UI設(shè)計(jì)文件

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>1139</width>
    <height>844</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="GraphicsLayoutWidget" name="graphicsLayout" native="true">
    <property name="geometry">
     <rect>
      <x>30</x>
      <y>20</y>
      <width>1091</width>
      <height>361</height>
     </rect>
    </property>
   </widget>
   <widget class="PlotWidget" name="graphPlot" native="true">
    <property name="geometry">
     <rect>
      <x>30</x>
      <y>390</y>
      <width>1091</width>
      <height>411</height>
     </rect>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>1139</width>
     <height>26</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <customwidgets>
  <customwidget>
   <class>GraphicsLayoutWidget</class>
   <extends>QWidget</extends>
   <header location="global">pyqtgraph.h</header>
   <container>1</container>
  </customwidget>
  <customwidget>
   <class>PlotWidget</class>
   <extends>QWidget</extends>
   <header location="global">pyqtgraph.h</header>
   <container>1</container>
  </customwidget>
 </customwidgets>
 <resources/>
 <connections/>
</ui>

UI生成文件

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'd:\project\python\pyqtgraph\PygraphDemo2\demo02.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1139, 844)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.graphicsLayout = GraphicsLayoutWidget(self.centralwidget)
        self.graphicsLayout.setGeometry(QtCore.QRect(30, 20, 1091, 361))
        self.graphicsLayout.setObjectName("graphicsLayout")
        self.graphPlot = PlotWidget(self.centralwidget)
        self.graphPlot.setGeometry(QtCore.QRect(30, 390, 1091, 411))
        self.graphPlot.setObjectName("graphPlot")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1139, 26))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        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", "MainWindow"))
from pyqtgraph import GraphicsLayoutWidget, PlotWidget

運(yùn)行效果

到此這篇關(guān)于PyQt5使用pyqtgraph繪制波形圖的文章就介紹到這了,更多相關(guān)PyQt5 pyqtgraph繪制波形圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python批量刪除txt文本指定行的思路與代碼

    Python批量刪除txt文本指定行的思路與代碼

    在深度學(xué)習(xí)項(xiàng)目中常常會(huì)處理各種數(shù)據(jù)集,下面這篇文章主要給大家介紹了關(guān)于Python批量刪除txt文本指定行的思路與代碼,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-02-02
  • Python中解決schedule模塊安裝與使用問題的完整指南

    Python中解決schedule模塊安裝與使用問題的完整指南

    在 Python 開發(fā)中,定時(shí)任務(wù)是一個(gè)非常常見的需求,schedule 是一個(gè)輕量級(jí)的 Python 庫,專門用于簡化定時(shí)任務(wù)的實(shí)現(xiàn),本文將圍繞 schedule 模塊的安裝與使用進(jìn)行詳細(xì)介紹,希望對(duì)大家有所幫助
    2025-03-03
  • python實(shí)現(xiàn)電子產(chǎn)品商店

    python實(shí)現(xiàn)電子產(chǎn)品商店

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)電子產(chǎn)品商店,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-02-02
  • Python實(shí)現(xiàn)二叉樹的常見遍歷操作總結(jié)【7種方法】

    Python實(shí)現(xiàn)二叉樹的常見遍歷操作總結(jié)【7種方法】

    這篇文章主要介紹了Python實(shí)現(xiàn)二叉樹的常見遍歷操作,結(jié)合實(shí)例形式總結(jié)分析了二叉樹的前序、中序、后序、層次遍歷中的迭代與遞歸等7種操作方法,需要的朋友可以參考下
    2019-03-03
  • PyTorch如何創(chuàng)建自己的數(shù)據(jù)集

    PyTorch如何創(chuàng)建自己的數(shù)據(jù)集

    這篇文章主要介紹了PyTorch如何創(chuàng)建自己的數(shù)據(jù)集,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • pandas 數(shù)據(jù)索引與選取的實(shí)現(xiàn)方法

    pandas 數(shù)據(jù)索引與選取的實(shí)現(xiàn)方法

    這篇文章主要介紹了pandas 數(shù)據(jù)索引與選取的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • python GUI庫圖形界面開發(fā)之PyQt5切換按鈕控件QPushButton詳細(xì)使用方法與實(shí)例

    python GUI庫圖形界面開發(fā)之PyQt5切換按鈕控件QPushButton詳細(xì)使用方法與實(shí)例

    這篇文章主要介紹了python GUI庫圖形界面開發(fā)之PyQt5切換按鈕控件QPushButton詳細(xì)使用方法與實(shí)例,需要的朋友可以參考下
    2020-02-02
  • Pandas自定義shift與DataFrame求差集的小技巧

    Pandas自定義shift與DataFrame求差集的小技巧

    Python是進(jìn)行數(shù)據(jù)分析的一種出色語言,主要是因?yàn)橐詳?shù)據(jù)為中心的python軟件包具有奇妙的生態(tài)系統(tǒng),下面這篇文章主要給大家介紹了關(guān)于Pandas自定義shift與DataFrame求差集的相關(guān)資料,需要的朋友可以參考下
    2022-02-02
  • 詳解Python中數(shù)據(jù)類型的轉(zhuǎn)換

    詳解Python中數(shù)據(jù)類型的轉(zhuǎn)換

    這篇文章主要為大家詳細(xì)介紹了Python中數(shù)據(jù)類型轉(zhuǎn)換的相關(guān)資料,文中的示例代碼講解詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴可以了解一下
    2023-03-03
  • OpenCv實(shí)現(xiàn)繪圖功能

    OpenCv實(shí)現(xiàn)繪圖功能

    這篇文章主要為大家詳細(xì)介紹了OpenCv實(shí)現(xiàn)繪圖功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-05-05

最新評(píng)論

桂平市| 临高县| 砚山县| 德州市| 盖州市| 应城市| 黄冈市| 扶绥县| 东乌珠穆沁旗| 务川| 阿城市| 高青县| 诸城市| 仲巴县| 南宁市| 泽普县| 留坝县| 通海县| 民勤县| 浮梁县| 宁明县| 满城县| 綦江县| 江城| 辉县市| 平顶山市| 汝城县| 泗阳县| 上蔡县| 凤城市| 青岛市| 德保县| 雷波县| 油尖旺区| 土默特左旗| 哈尔滨市| 东城区| 襄樊市| 毕节市| 朔州市| 浏阳市|