snippets.txt 1013 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Another way to do it without clearing the Axis
  2. from itertools import count
  3. import pandas as pd
  4. import matplotlib.pyplot as plt
  5. from matplotlib.animation import FuncAnimation
  6. plt.style.use('fivethirtyeight')
  7. x_vals = []
  8. y_vals = []
  9. plt.plot([], [], label='Channel 1')
  10. plt.plot([], [], label='Channel 2')
  11. def animate(i):
  12. data = pd.read_csv('data.csv')
  13. x = data['x_value']
  14. y1 = data['total_1']
  15. y2 = data['total_2']
  16. ax = plt.gca()
  17. line1, line2 = ax.lines
  18. line1.set_data(x, y1)
  19. line2.set_data(x, y2)
  20. xlim_low, xlim_high = ax.get_xlim()
  21. ylim_low, ylim_high = ax.get_ylim()
  22. ax.set_xlim(xlim_low, (x.max() + 5))
  23. y1max = y1.max()
  24. y2max = y2.max()
  25. current_ymax = y1max if (y1max > y2max) else y2max
  26. y1min = y1.min()
  27. y2min = y2.min()
  28. current_ymin = y1min if (y1min < y2min) else y2min
  29. ax.set_ylim((current_ymin - 5), (current_ymax + 5))
  30. ani = FuncAnimation(plt.gcf(), animate, interval=1000)
  31. plt.legend()
  32. plt.tight_layout()
  33. plt.show()