Plot.py 854 B

123456789101112131415161718192021222324252627282930313233
  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, plots = 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=(plots, points), dtype=float)
  14. self.i = 0
  15. self.points = points
  16. self.plots = plots
  17. def setTitle(self, title):
  18. self.ax.set_title('Windkanal')
  19. def update(self, values):
  20. self.ax.clear()
  21. for p in range(self.plots):
  22. self.ys[p, self.i] = values[p]
  23. self.ax.plot(self.xs, self.ys[p], "#00A3E0", label="{}. Graph".format(p+1))
  24. self.i = (self.i+1) % self.points
  25. self.ax.legend(bbox_to_anchor=(0, 1.02, 1, .102), loc=3, ncol=2, borderaxespad=0)