-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdemo.py
More file actions
63 lines (48 loc) · 1.4 KB
/
demo.py
File metadata and controls
63 lines (48 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import math
from pyside6qcustomplot import QCustomPlot, QCP
from PySide6.QtWidgets import QApplication
from PySide6.QtCore import QTimer, Qt
from PySide6.QtGui import QPen
app = QApplication([])
widget = QCustomPlot()
widget.setWindowTitle("QCustomPlot demo")
widget.setInteractions(QCP.iRangeDrag | QCP.iRangeZoom)
widget.setPlottingHint(QCP.PlottingHint.phFastPolylines, True)
widget.legend.setVisible(True)
widget.show()
widget.resize(800, 600)
g1 = widget.addGraph()
pen1 = QPen(Qt.blue)
pen1.setWidth(3)
g1.setPen(pen1)
g1.setName("First graph")
g2 = widget.addGraph()
pen2 = QPen(Qt.red)
pen2.setWidth(2)
g2.setPen(pen2)
g2.setName("Second graph")
widget.xAxis.setRange(-10, 400)
widget.xAxis.setLabel("Time [s]")
widget.yAxis.setRange(-10, 40)
widget.yAxis.setLabel("Value")
x = [t * 0.01 for t in range(100)]
y = [math.sin(v) for v in x]
y2 = [v+10 for v in y]
g1.setData(x, y)
g2.setData(x, y2)
t = x[-1]
def add_data():
global t
x = [t+dt * 0.01 for dt in range(100)]
t = x[-1]
y = [math.sin(v) for v in x]
y2 = [v+10 for v in y]
g1.addData(x, y)
g2.addData(x, y2)
widget.replot(QCustomPlot.RefreshPriority.rpQueuedReplot)
print('data size first graph:', g1.dataCount(), 'replot time:', widget.replotTime())
timer = QTimer()
timer.setInterval(60)
timer.timeout.connect(add_data)
timer.start()
app.exec()