-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtele_graph.py
More file actions
49 lines (34 loc) · 1.4 KB
/
tele_graph.py
File metadata and controls
49 lines (34 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
import pyqtgraph
from pyqtgraph import PlotWidget
class TelemetryGraph:
def __init__(self, graph, legend=False):
self._graph = graph
self._graph.setBackground('w')
self.styles = {'color': '#000000', 'font-size': '12px'}
self.y_limit = 30
self._x = dict()
self._y = dict()
self._lines = dict()
self._pen = dict()
if legend:
self._graph.addLegend(offset=(0, 0))
def addLine(self, name='default', color='black'):
self._x[name] = [0]
self._y[name] = [0]
self._pen[name] = pyqtgraph.mkPen(color=color)
self._lines[name] = self._graph.plot(self._x[name], self._y[name], name=name)
def plotData(self, x, y, name='default'):
self._x[name].append(x)
self._y[name].append(y)
if len(self._x[name]) > self.y_limit:
self._x[name] = self._x[name][1:]
self._y[name] = self._y[name][1:]
self._lines[name].setData(self._y[name], self._x[name], name=name, pen=self._pen[name])
def setBackgroundColor(self, color='w'):
self._graph.setBackground(color)
def setTitle(self, name, color='black'):
self._graph.setTitle(name, color=color, size='12pt')
def setYLabel(self, name):
self._graph.setLabel('left', name, **self.styles)
def setXLabel(self, name):
self._graph.setLabel('bottom', name, **self.styles)