12345678910111213141516171819202122232425262728293031323334353637383940 |
- import matplotlib
- from matplotlib.figure import Figure
- from matplotlib import style
- import numpy as np
- from .globals import *
- style.use("ggplot")
-
- class Plot():
- def __init__(self, points, lines = 1):
- matplotlib.use('TkAgg')
- self.fig = Figure()
- self.ax = self.fig.add_subplot(111)
- self.xs = range(points)
- self.ys = np.ndarray(shape=(lines, points), dtype=float)
- self.i = 0
- self.points = points
- self.plots = [None] * lines
- for p in range(lines):
- self.plots[p], = self.ax.plot(self.xs, self.ys[p], "#00A3E0", label="{}. Graph".format(p+1))
-
- self.ax.legend(bbox_to_anchor=(0, 1.02, 1, .102), loc=3, ncol=2, borderaxespad=0)
- def setTitle(self, title):
- self.ax.set_title(title)
- def update(self, values):
- self.ax.draw_artist(self.ax.patch)
- for p in range(len(self.plots)):
- self.ys[p] = np.append([values[p]], self.ys[p][:-1])
- self.plots[p].set_ydata(self.ys[p])
- self.ax.draw_artist(self.plots[p])
-
- self.fig.canvas.draw()
- self.i = (self.i+1) % self.points
-
|