Plot.py 858 B

123456789101112131415161718192021222324252627282930
  1. import numpy as np
  2. from .globals import *
  3. from .plotim import linear_plot
  4. class Plot(linear_plot):
  5. def __init__(self, nPoints, xaxis, yaxis, nGraphs = 1, **kwargs):
  6. self.xs = np.ndarray(shape=(nGraphs, nPoints), dtype=float)
  7. self.xs.fill(0)
  8. self.ys = np.ndarray(shape=(nGraphs, nPoints), dtype=float)
  9. self.ys.fill(float('NaN'))
  10. self.i = 0
  11. self.nPoints = nPoints
  12. self.nGraphs = nGraphs
  13. linear_plot.__init__(self, **kwargs)
  14. self.set_scale(xaxis, yaxis)
  15. def update(self, ys, xs=None, visible=True):
  16. for g in range(self.nGraphs):
  17. if xs == None:
  18. self.xs[g][self.i] = self.i
  19. else:
  20. self.xs[g] = np.append([xs[g]], self.xs[g][:-1])
  21. self.ys[g] = np.append([ys[g]], self.ys[g][:-1])
  22. if visible:
  23. self.plot_data(self.xs, self.ys)
  24. self.i = (self.i+1) % self.nPoints