設為首頁收藏本站

艾歐踢論壇

 找回密碼
 立即註冊

QQ登錄

只需一步,快速開始

搜索
熱搜: 活動 交友 discuz
查看: 326|回復: 0
打印 上一主題 下一主題

PyQtGraph plotting over time

[複製鏈接]
跳轉到指定樓層
樓主
發表於 2023-4-24 15:20:59 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
  1. from PyQt5 import QtWidgets, QtCore
  2. from pyqtgraph import PlotWidget, plot
  3. import pyqtgraph as pg
  4. import sys  # We need sys so that we can pass argv to QApplication
  5. import os
  6. from random import randint

  7. class MainWindow(QtWidgets.QMainWindow):

  8.     def __init__(self, *args, **kwargs):
  9.         super(MainWindow, self).__init__(*args, **kwargs)

  10.         self.graphWidget = pg.PlotWidget()
  11.         self.setCentralWidget(self.graphWidget)

  12.         self.x = list(range(100))  # 100 time points
  13.         self.y = [randint(0,100) for _ in range(100)]  # 100 data points

  14.         self.graphWidget.setBackground('w')

  15.         pen = pg.mkPen(color=(255, 0, 0))
  16.         self.data_line =  self.graphWidget.plot(self.x, self.y, pen=pen)

  17.         self.timer = QtCore.QTimer()
  18.         self.timer.setInterval(50)
  19.         self.timer.timeout.connect(self.update_plot_data)
  20.         self.timer.start()

  21.     def update_plot_data(self):

  22.         self.x = self.x[1:]  # Remove the first y element.
  23.         self.x.append(self.x[-1] + 1)  # Add a new value 1 higher than the last.

  24.         self.y = self.y[1:]  # Remove the first
  25.         self.y.append( randint(0,100))  # Add a new random value.

  26.         self.data_line.setData(self.x, self.y)  # Update the data.


  27. app = QtWidgets.QApplication(sys.argv)
  28. w = MainWindow()
  29. w.show()
  30. sys.exit(app.exec_())
複製代碼
Matplotlib 轉移至 PyQtGraph 製作Real Time Curve
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 轉播轉播 分享分享 分享淘帖
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

小黑屋|Archiver|手機版|艾歐踢創新工坊    

GMT+8, 2024-4-29 19:42 , Processed in 0.232174 second(s), 18 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表