StateEventLocation_experiment.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/python3
  2. # This file was automatically generated from drawio2cbd with the command:
  3. # /home/red/git/DrawioConvert/__main__.py StateEventLocation.xml -fav -F CBD -e Experiment -t 100 -E delta=0.1
  4. from CBD.lib.interface.plotting import SignalPlotBlock
  5. from CBD.simulator import Simulator
  6. from StateEventLocation import *
  7. import matplotlib.pyplot as plt
  8. import matplotlib.animation as animation
  9. DELTA_T = 0.1
  10. fig = plt.figure(figsize=(15, 5), dpi=100)
  11. ax1 = fig.add_subplot(1, 1, 1)
  12. ax2 = ax1.twinx()
  13. cbd = Experiment("Experiment", ax1, ax2)
  14. plotter1 = cbd.getBlockByName("valueplot")
  15. plotter2 = cbd.getBlockByName("eventplot")
  16. # opened = True
  17. # def term(*_):
  18. # global opened
  19. # plt.draw()
  20. # plt.pause(0.001)
  21. # return not opened
  22. # def animate(_, p):
  23. # px = p.state["x"]
  24. # py = p.state["y"]
  25. # p.elem.set_data(px, py)
  26. # try:
  27. # p.elem.axes.set_xlim((min(px), max(px)))
  28. # p.elem.axes.set_ylim((min(py), max(py)))
  29. # except: pass
  30. # return p.elem,
  31. # Run the Simulation
  32. sim = Simulator(cbd)
  33. sim.setRealTime(True)
  34. # sim.setTerminationCondition(term)
  35. # def handle_close(evt):
  36. # global opened
  37. # opened = False
  38. # fig.canvas.mpl_connect('close_event', handle_close)
  39. # plt.ion()
  40. # plt.show()
  41. # ani1 = animation.FuncAnimation(fig, animate, fargs=(plotter1,), interval=200)
  42. # ani2 = animation.FuncAnimation(fig, animate, fargs=(plotter2,), interval=200)
  43. # plotter1.set_animation(fig)
  44. # plotter2.set_animation(fig)
  45. # plotter1.start_animation(fig)
  46. sim.run(20.0)
  47. # plt.ioff()
  48. # plotter1.end_animation()
  49. # plotter2.end_animation()
  50. log = sim.getDurationLog()
  51. fig2 = plt.figure()
  52. ax2 = fig2.subplots()
  53. ax2.bar(range(len(log)), log)
  54. plt.show()