Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. from matplotlib.lines import Line2D
  3. import matplotlib.animation as animation
  4.  
  5.  
  6. class SubplotAnimation(animation.TimedAnimation):
  7.  
  8. def __init__(self):
  9. fig = plt.figure()
  10. ax1 = fig.add_subplot(1, 1, 1)
  11.  
  12. ax1.set_xlabel('Time')
  13. ax1.set_ylabel('Energy/sec')
  14.  
  15. self.line1 = Line2D([], [], color='black')
  16.  
  17. ax1.add_line(self.line1)
  18.  
  19. ax1.set_xlim(0, 20)
  20. ax1.set_ylim(0, 5)
  21. #ax1.set_aspect('equal', 'datalim')
  22.  
  23. animation.TimedAnimation.__init__(self, fig, interval=50, blit=True)
  24.  
  25.  
  26. def _draw_frame(self, framedata):
  27.  
  28. self.x, self.y = self.pull_data()
  29.  
  30. self.line1.set_data(self.x, self.y)
  31.  
  32. self._drawn_artists = [self.line1]
  33.  
  34.  
  35. def pull_data(self):
  36.  
  37. data = open('sample_plot.txt', 'r').read()
  38. data_list = data.split('\n')
  39. x_list = []
  40. y_list = []
  41. for line in data_list:
  42. if len(line) > 1:
  43.  
  44. x, y = line.split(',')
  45. x_list.append(int(x))
  46. y_list.append(int(y))
  47.  
  48. return x_list, y_list
  49.  
  50.  
  51. def new_frame_seq(self):
  52. #print('new_frame_seq')
  53. return iter(range(1))
  54.  
  55.  
  56. def _init_draw(self):
  57. #print('_init_draw')
  58. lines = [self.line1]
  59. for l in lines:
  60. l.set_data([], [])
  61.  
  62.  
  63.  
  64. ani = SubplotAnimation()
  65. #ani.save('test_sub.mp4')
  66. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement