Graph.py 2.03 KB
Newer Older
1
from pyqtgraph import PlotItem,AxisItem,GridItem
2
3
4
import time


5
6
class Graph(PlotItem):
    index = 0
7

8
    def __init__(self,x_sampling, x_range, n_axis, y_min, y_max, x_size, y_size, color, name,unit):
9
        super(Graph, self).__init__()
10
11
        self.x_sampling=1
        self.x_range = x_range/x_sampling
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

        self.curve = []
        self.axis = []
        self.y=[]

        self.curve.append(self.plot(pen=color[0], name=name[0]))
        self.axis.append(AxisItem("left",color[0]))
        self.axis[0].setLabel(name[0], unit[0])
        self.axis[0].setRange(y_min[0], y_max[0])

        y_axis = [0]
        self.y.append(y_axis)


        try:
            for n in range(1,n_axis):
                self.curve.append(self.plot(pen=color[n], name=name[n]))
                self.axis.append(AxisItem("right",color[n]))
                self.axis[n].setLabel(name[n],unit[n])
                self.axis[n].setRange(y_min[n],y_max[n])
                self.y.append(y_axis)
                print(y_axis)
        except Exception as e:
            print(e)
36

37
38
        self.axisTime = AxisItem("bottom", 'w')
        self.axisTime.setLabel("Tempo", 's')
39
40
41
        self.axisTime.setRange(0, x_range)
        self.x=[]
        self.x.append(0)
42

43
44
        self.showAxis("left", False)
        self.showAxis("bottom", False)
45

46
        self.setMinimumSize(x_size, y_size)
47

48
        self.setXRange(0, self.x_range, padding=0)
49
        self.setYRange(min(y_min), max(y_max), padding=0)
Alisson Claudino's avatar
Alisson Claudino committed
50

51
        self.timeant = time.time()
52
53


54
    def updateGraph(self, y):
55
        # print(time.time()-self.timeant)
56
57
58
59
60
61
62
63
64
65


        for n in range(0,len(y)):
            print(y[n])
            print(self.y[n])
            self.y[n].append(y[n])

        if len(self.y[0]) > self.x_range+1 :
            for n in range(0,len(y)):
                self.y[n].pop(0)
66
67
            self.index = self.x_range
        else:
68
69
            self.x.append(self.index)

70
71
        self.index = self.index + 1

72
73
74
75
76

        for n in range(0,len(y)):
            self.curve[0].setData(self.x, self.y[0])

        self.timeant = time.time()