Plot.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import matplotlib
  2. from matplotlib.figure import Figure
  3. from matplotlib import style
  4. import numpy as np
  5. from .globals import *
  6. style.use("ggplot")
  7. class Plot():
  8. def __init__(self, points, lines = 1):
  9. matplotlib.use('TkAgg')
  10. self.fig = Figure()
  11. self.ax = self.fig.add_subplot(111)
  12. self.xs = range(points)
  13. self.ys = np.ndarray(shape=(lines, points), dtype=float)
  14. self.i = 0
  15. self.points = points
  16. self.plots = [None] * lines
  17. for p in range(lines):
  18. self.plots[p], = self.ax.plot(self.xs, self.ys[p], "#00A3E0", label="{}. Graph".format(p+1))
  19. self.ax.legend(bbox_to_anchor=(0, 1.02, 1, .102), loc=3, ncol=2, borderaxespad=0)
  20. def setTitle(self, title):
  21. self.ax.set_title(title)
  22. def update(self, values):
  23. self.ax.draw_artist(self.ax.patch)
  24. for p in range(len(self.plots)):
  25. self.ys[p] = np.append([values[p]], self.ys[p][:-1])
  26. self.plots[p].set_ydata(self.ys[p])
  27. self.ax.draw_artist(self.plots[p])
  28. self.fig.canvas.draw()
  29. self.i = (self.i+1) % self.points