How To Plot Data Curves in Pyqtgraph | Data Visualization In PyQt

preview_player
Показать описание
Join PyQt6 13 Hours Course in Udemy

In this video i want to show you How To Plot Data Curves in Pyqtgraph.

Get the source codes:
Рекомендации по теме
Комментарии
Автор

Any suggestions how to plot live, real-time data using de-queue/pipes? I have a process that receives data from the serial port that I want to send to pyqtgraph for fast plotting!

For example, the github Haschtl/RealTimeOpenControl :

from collections import deque
from PyQt5 import QtWidgets, QtCore, QtGui
import stack
import pyqtgraph as pg
import random

class ExampleApp(QtWidgets.QMainWindow, stack.Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
Value', color='#0000ff')
self.graphicsView.getAxis('bottom').setLabel('time', 's')
self.graphicsView.showGrid(x=True, y=True)
self.graphicsView.setYRange(0, 10)
self.graphicsView.addLine(y=5, pen=pg.mkPen('y'))
self.graphicsView.addLine(y=7, pen=pg.mkPen('r'))
self.curve = self.graphicsView.plot()
self.L = deque([0], maxlen=10)
self.t = deque([0], maxlen=10)

self.timer = QtCore.QTimer(self)

self.timer.start(500)

self.timer = QtCore.QTimer()

self.timer.setInterval(50)

self.timer.start()

def update_plot_data(self):

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

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

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

def updateplot(self):
val = round(random.uniform(0, 10), 2)
self.L.append(val)
self.t.append(self.t[-1]+1)
self.curve.setData(self.t, self.L)








from PyQt5 import QtWidgets, QtCore
from pyqtgraph import PlotWidget, plot
import pyqtgraph as pg
import sys # We need sys so that we can pass argv to QApplication
import os
from random import randint

class

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

self.graphWidget = pg.PlotWidget()


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



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


app =
w = MainWindow()
w.show()
sys.exit(app.exec_())







## -*- coding: utf-8 -*-
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from pyqtgraph import PlotWidget
import pyqtgraph
import numpy as np
import serial

class
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)

self.plot_data = {
'ax':np.full(100, 0),
'ay':np.full(100, 0),
'az':np.full(100, 0),
'gx':np.full(100, 0),
'gy':np.full(100, 0),
'gz':np.full(100, 0),
'mx':np.full(100, 0),
'my':np.full(100, 0),
'mz':np.full(100, 0),
't' :np.arange(100)
}

self.plot_data_color = {
'ax':'#FF0000',
'ay':'#00FF00',
'az':'#0000FF',
'gx':'#DDDD00',
'gy':'#00DDDD',
'gz':'#DD00DD',
'mx':'#808020',
'my':'#208080',
'mz':'#802080'
}

self.resize(600, 600)
{background: 'white';}")
self.serial = serial.Serial('COM3', 115200, timeout=None)

# leyout
self.centralwidget = QtWidgets.QWidget(self)

self.verticalLayout =

# pot widget
self.plotwidget = { axis:PlotWidget(self) for axis in ['a', 'g', 'm'] }
titles = { 'a':'Acceleration', 'g':'Gyro', 'm':'Geomagnetism' }
for key in self.plotwidget:

plotitem =
plotitem.setLabels(bottom='time', left=titles[key])
)
)

# leyout




# timer
self.timer = QtCore.QTimer()

self.timer.start(50)

def update_data(self):
# stop timer
self.timer.stop()

# clear
self.plotwidget['a'].clear()
self.plotwidget['g'].clear()
self.plotwidget['m'].clear()

# get serial
try:
line =
data = { for data in line.split(', ') }

# increase time
self.plot_data['t'] = np.append( self.plot_data['t'][1:], self.plot_data['t'][-1]+1 )

# add data
for key in self.plot_data:
if key == 't':
continue
self.plot_data[key] = np.append( self.plot_data[key][1:], float(data[key]) )

# set data

pyqtgraph.PlotDataItem(
x=self.plot_data['t'], y=self.plot_data[key],
pen=pyqtgraph.mkPen(color=self.plot_data_color[key], width=3), antialias=True
)
)
except:
pass

# start timer
self.timer.start(50)

def main():
app =
mainwindow = MainWindow(None)
mainwindow.show()
app.exec()

if __name__ == '__main__':
main()

bennguyen
Автор

Kindly show how to ADD a secondary Y Axis in PyQt5 and pyqtgraph

soulonfiretv
Автор

How to add these graphs in one of the frame in qtwindow application where one frame contain graph 1 and another contain graph 2

amityadav
join shbcf.ru