亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

PyQt5使用pyqtgraph繪制波形圖

 更新時間:2023年01月13日 16:24:02   作者:SongYuLong的博客  
pyqtgraph是Python平臺上一種功能強大的2D/3D繪圖庫,相當于matplotlib庫,比它更強大。本文就來利用pyqtgraph實現(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) # 設置開啟抗鋸齒

        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() # 圖像坐標換行
        plt3 = self.graphicsLayout.addPlot(y=np.random.normal(size=800), title="光照度")
        plt4 = self.graphicsLayout.addPlot(y=np.random.normal(size=800), title="紫外線強度")


    # 在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界面設計

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

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

GraphicsLayoutWidget類型通過addPlot方法添加波形數(shù)據(jù),每個波形都占有獨立的區(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)多個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設計文件

<?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

運行效果

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

相關文章

  • Python詳細講解圖像處理的而兩種庫OpenCV和Pillow

    Python詳細講解圖像處理的而兩種庫OpenCV和Pillow

    這篇文章介紹了Python使用OpenCV與Pillow分別進行圖像處理的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-06-06
  • Python中生成一個指定長度的隨機字符串實現(xiàn)示例

    Python中生成一個指定長度的隨機字符串實現(xiàn)示例

    這篇文章主要介紹了Python中生成一個指定長度的隨機字符串,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-11-11
  • python實現(xiàn)將文件夾內(nèi)的每張圖片批量分割成多張

    python實現(xiàn)將文件夾內(nèi)的每張圖片批量分割成多張

    這篇文章主要為大家詳細介紹了python實現(xiàn)將文件夾內(nèi)的每張圖片批量分割成多張,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • Python實現(xiàn)提取Word文檔中的文本和圖片

    Python實現(xiàn)提取Word文檔中的文本和圖片

    將內(nèi)容從?Word?文檔中提取出來可以方便我們對其進行其他操作,如將內(nèi)容儲存在數(shù)據(jù)庫中,本文將介紹如何使用簡單的代碼實現(xiàn)從?Word?文檔中提取文本和圖片內(nèi)容并保存,需要的可以參考下
    2023-12-12
  • 淺析Python中的for 循環(huán)

    淺析Python中的for 循環(huán)

    這篇文章主要介紹了淺析Python中的for 循環(huán)的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-06-06
  • OpenCV實現(xiàn)圖像平滑處理的方法匯總

    OpenCV實現(xiàn)圖像平滑處理的方法匯總

    這篇文章為大家詳細介紹了在圖像上面進行了圖像均值濾波、方框濾波 、高斯濾波、中值濾波、雙邊濾波、2D卷積等具體操作的方法,需要的可以參考一下
    2023-02-02
  • python re的findall和finditer的區(qū)別詳解

    python re的findall和finditer的區(qū)別詳解

    這篇文章主要介紹了python re的findall和finditer的區(qū)別詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-11-11
  • python爬蟲的工作原理

    python爬蟲的工作原理

    本文主要介紹了python爬蟲的工作原理,具有很好的參考價值。下面跟著小編一起來看下吧
    2017-03-03
  • 基于Python的OCR實現(xiàn)示例

    基于Python的OCR實現(xiàn)示例

    這篇文章主要介紹了基于Python的OCR實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-04-04
  • Python web如何在IIS發(fā)布應用過程解析

    Python web如何在IIS發(fā)布應用過程解析

    這篇文章主要介紹了Python web如何在IIS發(fā)布應用過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-05-05

最新評論