Guest User

Untitled

a guest
Feb 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. def plot(self):
  2. import matplotlib.pyplot as plt
  3. plt.ion()
  4. self.fig,self.axis = plt.subplots()
  5. self.line, = plt.plot([1,2],[10,10],color = '#A9F5D0', label="# Monitor Peers", marker='o', ls='None', markeredgecolor='#A9F5D0', animated=True)
  6. plt.axis([0, 100, 0, 101])
  7. self.fig.canvas.draw()
  8. self.line.set_xdata(self.x)
  9.  
  10. def update(self,y):
  11. self.line.set_ydata(y)
  12. self.axis.draw_artist(self.line)
  13. self.fig.canvas.blit(self.axis.bbox)
  14. self.fig.canvas.flush_events()
  15.  
  16.  
  17. def store(self):
  18. drawing_log_file = open("test.txt", "w", 1)
  19. drawing_log_file.write(str(self.n)+'n')
  20.  
  21. # Configuration in the first line
  22.  
  23. while True:
  24. time.sleep(0.1)
  25. y = np.random.randint(0,100,self.n)
  26. # f.write("n".join(map(lambda x: str(x), mylist)))
  27. drawing_log_file.write(" ".join(map(str, y))+'n')
  28.  
  29. drawing_log_file.write("Bye")
  30. drawing_log_file.close()
  31.  
  32.  
  33. def draw(self):
  34. self.plot()
  35. time.sleep(2)
  36. file = open("test.txt","r")
  37.  
  38. while True:
  39. time.sleep(2)
  40. line = file.readline()
  41. y = line.strip().split(" ", self.n)
  42. self.update(y)
  43.  
  44. def run(self):
  45. Process(target=self.store).start()
  46. time.sleep(5)
  47. p = Process(target=self.draw)
  48. p.start()
  49.  
  50. fire.Fire(Simulation)`
Add Comment
Please, Sign In to add comment