SinGen_matplotlib_experiment.py 974 B

123456789101112131415161718192021222324252627
  1. from SinGen import *
  2. from CBD.realtime.plotting import PlotManager, LinePlot, follow
  3. from CBD.simulator import Simulator
  4. import matplotlib.pyplot as plt
  5. sinGen = SinGen("sin")
  6. fig = plt.figure(figsize=(5, 5), dpi=100)
  7. ax = fig.add_subplot(111)
  8. ax.set_ylim((-1, 1)) # The sine wave never exceeds this range
  9. plot = fig, ax
  10. manager = PlotManager()
  11. manager.register("sin", sinGen.find('collector')[0], plot, LinePlot(color='red'))
  12. # manager.connect('sin', 'update', lambda d, axis=ax: axis.set_xlim(follow(d[0], 10.0, lower_bound=0.0)))
  13. manager.connect('sin', 'update', lambda d, p=plot: manager.set_xlim(p, follow(d[0], 10.0, lower_bound=0.0)))
  14. # NOTE: alternatively, the CBD.realtime.plotting.set_xlim method can be used:
  15. # from CBD.realtime.plotting import set_xlim
  16. # manager.connect('sin', 'update', lambda d, p=plot: manager.set_xlim(p, follow(d[0], 10.0, lower_bound=0.0)))
  17. sim = Simulator(sinGen)
  18. sim.setRealTime()
  19. sim.setDeltaT(0.1)
  20. sim.run(20.0)
  21. plt.show()