Newer
Older
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
import numpy as np
import pyqtgraph as pg
from PySide6.QtWidgets import QWidget, QSizePolicy
from PySide6.QtGui import QLinearGradient, QBrush, QColor
from app.ui.dist.ui_module import Ui_module
class Module(QWidget, Ui_module):
"""Handles all the post-processing settings of an `experiment` object."""
def __init__(self):
super().__init__()
self.setupUi(self)
self.graph = Graph()
self.graph.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self.graph.setFixedSize(500, 200)
view_box = self.graph.getViewBox()
# Disable mouse interactivity (zoom, pan)
view_box.setMouseEnabled(x=False, y=False)
# view_box.setInteractive(False)
data_count = 100
self.x = np.arange(data_count)
self.y = np.zeros(data_count)
y2 = np.zeros(data_count)
self.curve = self.graph.plot(self.x, self.y, pen=pg.mkPen(QColor(237, 240, 96), width=2))
curve2 = self.graph.plot(self.x, y2, pen=pg.mkPen(QColor(0, 0, 255, 0), width=0))
# Create a gradient brush
gradient = QLinearGradient(0, 0, 0, 1)
gradient.setCoordinateMode(QLinearGradient.ObjectBoundingMode)
gradient.setColorAt(0, QColor(237, 240, 96, 10)) # Blue at the bottom, semi-transparent
gradient.setColorAt(1, QColor(237, 240, 96, 100)) # Transparent at the top
brush = QBrush(gradient)
# Fill the area under the curve with the gradient brush
fill = pg.FillBetweenItem(self.curve, curve2, brush=brush)
self.graph.addItem(fill)
self.graph.showGrid(x=True, y=True, alpha=0.3)
self.graph.getPlotItem().hideAxis('bottom')
self.graph_layout.addWidget(self.graph)
def update_plot_data(self, new_y):
# Update y data with a new sine wave that changes over time
self.y[:-1] = self.y[1:]
self.y[-1] = new_y
self.curve.setData(self.x, self.y)
class Graph(pg.PlotWidget):
"""Handles all the post-processing settings of an `experiment` object."""
def __init__(self, parent=None):
super(Graph, self).__init__(parent)
self.setBackground("#2c2e36")
self.color_white = '#f2f2f2'
self.pen = pg.mkPen(color="#EDF060", width=1)
self.label_styles = {'color':'#a2a2a2', 'font-size':'14px'}