-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_window.py
More file actions
69 lines (61 loc) · 2.14 KB
/
plot_window.py
File metadata and controls
69 lines (61 loc) · 2.14 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
64
65
66
67
68
69
from PyQt5.QtWidgets import (
QVBoxLayout,
QWidget,
QGraphicsView,
QGraphicsScene,
)
from PyQt5.QtCore import Qt
import pyqtgraph as pg
class PlotWindow(QWidget):
def __init__(self, channel):
super().__init__()
self.channel = channel
self.initUI()
def initUI(self):
self.setWindowTitle(f"Plot of channel {self.channel}")
self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint)
layout = QVBoxLayout()
self.graphicsView = QGraphicsView()
layout.addWidget(self.graphicsView)
self.setLayout(layout)
self.scene = QGraphicsScene()
self.graphicsView.setScene(self.scene)
self.plotWidget = pg.PlotWidget()
self.plotWidget.setLabel("bottom", "Time")
self.plotWidget.setTitle(f"Output current channel {self.channel}")
self.scene.addWidget(self.plotWidget)
def update_plot(self, voltage_data, current_data):
self.plotWidget.clear()
max_value = max(voltage_data)
min_value = min(voltage_data)
range_padding = 0.3 * (max_value - min_value)
y_min = min_value - range_padding
y_max = max_value + range_padding
if max_value >= 1:
self.plotWidget.setLabel("left", "Current (A)")
self.plotWidget.plot(
voltage_data, pen="b", symbol="o", symbolSize=5, symbolBrush=("g")
)
elif max_value >= 0.001:
self.plotWidget.setLabel("left", "Current (mA)")
y_min *= 1000
y_max *= 1000
self.plotWidget.plot(
[x * 1000 for x in voltage_data],
pen="g",
symbol="o",
symbolSize=5,
symbolBrush=("g"),
)
else:
self.plotWidget.setLabel("left", "Current (uA)")
y_min *= 1000000
y_max *= 1000000
self.plotWidget.plot(
[x * 1000000 for x in voltage_data],
pen="g",
symbol="o",
symbolSize=5,
symbolBrush=("g"),
)
# self.plotWidget.setYRange(y_min, y_max)