Advertisement
Guest User

Untitled

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