Guest User

Untitled

a guest
Oct 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. main.py
  5. """
  6. __author__ = "take-iwiw"
  7. __copyright__ = "Copyright 2017, take-iwiw"
  8. __date__ = "18 Oct 2017"
  9.  
  10. import numpy as np
  11. import matplotlib.pyplot as plt
  12. import matplotlib.cm as cm
  13. import pandas as pd
  14. import time
  15. import matplotlib.animation as animation
  16.  
  17. NUMBER_X: int = 10
  18. NUMBER_Y: int = 10
  19.  
  20. CANVAS_WIDTH: int = 10
  21. CANVAS_HEIGHT: int = 10
  22.  
  23. def heatmap_animation1():
  24. fig, ax_lst = plt.subplots(NUMBER_X, NUMBER_Y)
  25. ax_lst = ax_lst.ravel()
  26.  
  27. def plot(data):
  28. data = np.random.rand(CANVAS_WIDTH, CANVAS_HEIGHT)
  29. heatmap = ax_lst[0].pcolor(data)
  30.  
  31. ani = animation.FuncAnimation(fig, plot, interval=1)
  32. plt.show()
  33.  
  34. def heatmap_animation2():
  35. fig, ax_lst = plt.subplots(NUMBER_X, NUMBER_Y)
  36. ax_lst = ax_lst.ravel()
  37.  
  38. data = np.random.rand(CANVAS_WIDTH, CANVAS_HEIGHT)
  39. im = ax_lst[0].imshow(data)
  40.  
  41. while True:
  42. t_start = time.time()
  43. data = np.random.rand(CANVAS_WIDTH, CANVAS_HEIGHT)
  44. im.set_data(data)
  45. plt.pause(0.001)
  46. t_end = time.time()
  47. print("fps = {0}".format(999 if t_end == t_start else 1/(t_end-t_start)))
  48.  
  49. def heatmap_animation3():
  50. fig, ax_lst = plt.subplots(NUMBER_X, NUMBER_Y)
  51. ax_lst = ax_lst.ravel()
  52.  
  53. data = np.random.rand(CANVAS_WIDTH, CANVAS_HEIGHT)
  54. heatmap = ax_lst[0].pcolor(data)
  55. fig.canvas.draw()
  56. fig.show()
  57.  
  58. while True:
  59. data = np.random.rand(CANVAS_WIDTH, CANVAS_HEIGHT)
  60. t_start = time.time()
  61. heatmap = ax_lst[0].pcolor(data)
  62. ax_lst[0].draw_artist(ax_lst[0].patch)
  63. ax_lst[0].draw_artist(heatmap)
  64. fig.canvas.blit(ax_lst[0].bbox)
  65. fig.canvas.flush_events()
  66. t_end = time.time()
  67. print("fps = {0}".format(999 if t_end == t_start else 1/(t_end-t_start)))
  68.  
  69.  
  70. def main():
  71. """
  72. Entry function
  73. :called when: the program starts
  74. :param none: no parameter
  75. :return: none
  76. :rtype: none
  77. """
  78. heatmap_animation3()
  79.  
  80.  
  81.  
  82. if __name__ == '__main__':
  83. main()
Add Comment
Please, Sign In to add comment