-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataplot.py
More file actions
25 lines (21 loc) · 779 Bytes
/
dataplot.py
File metadata and controls
25 lines (21 loc) · 779 Bytes
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
import matplotlib.pyplot as plt
import matplotlib.animation as animation
class Dataplot:
def __init__(self, limit=20):
self.limit = limit
self.plots = {}
def add_subplot(self, name, title=None, xlabel=None, ylabel=None):
ax = plt.subplot(9, 1, len(self.plots)+1)
plt.xlabel = xlabel
plt.ylabel = ylabel
ax.title.set_text(title)
self.plots[name] = {'ax': ax, 'x': [], 'y': []}
def update_data(self, name, x, y):
self.plots[name]['x'].append(x)
self.plots[name]['x'] = self.plots[name]['x'][-self.limit:]
self.plots[name]['y'].append(y)
self.plots[name]['y'] = self.plots[name]['y'][-self.limit:]
self.plots[name]['ax'].clear()
self.plots[name]['ax'].plot(self.plots[name]['x'], self.plots[name]['y'], '.')
def get_plots(self):
return self.plots