Animation.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import matplotlib
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. def combination_rotation_animation(x, y, z, begin, amoung, step):
  5. from matplotlib.animation import PillowWriter, FFMpegWriter
  6. metadata = dict(title="Movie")
  7. writer1 = PillowWriter(fps=15, metadata=metadata)
  8. writer2 = FFMpegWriter(fps=15, metadata=metadata)
  9. for j in writer1, writer2:
  10. if j == writer1:
  11. text = ".gif"
  12. else:
  13. text = ".mp4"
  14. fig = plt.figure(figsize=(12, 12), dpi=100)
  15. ax = fig.add_subplot(projection='3d')
  16. interval = 360 / amoung
  17. count = 0
  18. start = 0
  19. total = 360
  20. with j.saving(fig, "B_animate"+text, 100):
  21. for i in tqdm.tqdm(np.linspace(-180, 180, total)):
  22. ax.clear()
  23. count += 360 / total
  24. if count > interval:
  25. count = 0
  26. start += step
  27. x1, kx = find_max_min(x[start: start + step])
  28. y1, ky = find_max_min(y[start: start + step])
  29. z1, kz = find_max_min(z[start: start + step])
  30. x2, y2, z2 = elipse(kx, ky, kz)
  31. ax.plot_wireframe(x2, y2, z2, linewidth=0.1, color='b')
  32. ax.scatter(x1, y1, z1, c='black',
  33. marker=">")
  34. ax.view_init(azim=i, elev=28)
  35. date_begin = date(2023, 1, 1) + timedelta(days=df_B.iloc[begin+start]["Day"])
  36. plt.title(
  37. "Day: " + str(date_begin) + " Hour: " + str(df_B.iloc[begin+start]["Hour"]) + " - " + str(
  38. df_B.iloc[begin + start + step]["Hour"]) + " Point: " + str(begin+start) + " - " + str(begin + start + step), size=20)
  39. plt.xlabel('$Bx$', size=20, color='g')
  40. plt.ylabel('$By$', size=20, color='g')
  41. ax.set_zlabel('$Bz$', size=20)
  42. j.grab_frame()
  43. def velocity_rotation(x, y, z, begin, amoung, step):
  44. from matplotlib.animation import PillowWriter, FFMpegWriter
  45. metadata = dict(title="Movie")
  46. writer1 = PillowWriter(fps=15, metadata=metadata)
  47. writer2 = FFMpegWriter(fps=15, metadata=metadata)
  48. for j in writer1, writer2:
  49. if j == writer1:
  50. text = ".gif"
  51. else:
  52. text = ".mp4"
  53. fig = plt.figure(figsize=(12, 12), dpi=100)
  54. ax = fig.add_subplot(projection='3d')
  55. interval = 360 / amoung
  56. count = 0
  57. start = 0
  58. total = 360
  59. with j.saving(fig, "V_animate" + text, 100):
  60. for i in tqdm.tqdm(np.linspace(-180, 180, total)):
  61. ax.clear()
  62. count += 360 / total
  63. if count > interval:
  64. count = 0
  65. start += step
  66. ax.scatter(x[start: start + step], y[start: start + step], z[start: start + step], c='black',
  67. marker=">")
  68. ax.view_init(azim=i, elev=28)
  69. date_begin = date(2023, 1, 1) + timedelta(days=df_V.iloc[begin + start]["Day"]-1)
  70. plt.title("Day: " + str(date_begin), size=20)
  71. plt.xlabel('$Vx$', color='g', size=20)
  72. plt.ylabel('$Vy$', color='g', size=20)
  73. ax.set_zlabel('$Vz$', size=20)
  74. j.grab_frame()
  75. def animation_rotate(x, y, z):
  76. from matplotlib.animation import PillowWriter
  77. metadata = dict(title="Movie")
  78. writer = PillowWriter(fps=15, metadata=metadata)
  79. fig = plt.figure(figsize=(12, 12), dpi=100)
  80. ax = fig.add_subplot(projection='3d')
  81. with writer.saving(fig, "V_animate.gif", 100):
  82. for i in np.linspace(-180, 180, 1440):
  83. ax.clear()
  84. ax.scatter(x, y, z, c='black', marker=">")
  85. ax.view_init(azim=i, elev=28)
  86. plt.xlabel('$Vx$', color='g')
  87. plt.ylabel('$Vy$', color='g')
  88. ax.set_zlabel('$Vz$')
  89. writer.grab_frame()
  90. def Anime(x, y, z, len_step):
  91. from matplotlib.animation import PillowWriter
  92. metadata = dict(title="Movie")
  93. writer = PillowWriter(fps=15, metadata=metadata)
  94. fig = plt.figure(figsize=(12, 12), dpi=100)
  95. ax = fig.add_subplot(projection='3d')
  96. def update(i):
  97. ax.clear()
  98. ax.scatter(x[i * len_step:i * len_step + len_step], y[i * len_step:i * len_step + len_step],
  99. z[i * len_step:i * len_step + len_step], s=0.5)
  100. plt.title(str(i * len_step))
  101. plt.xlabel('$Bx$', color='g')
  102. plt.ylabel('$By$', color='g')
  103. ax.set_zlabel('$Bz$')
  104. ani = animation.FuncAnimation(fig, update, np.arange(100), interval=1000, repeat=False)
  105. with writer.saving(fig, "Banimate-fix.gif", 100):
  106. for i in range(100):
  107. ax.clear()
  108. ax.scatter(x[i * len_step:i * len_step + len_step], y[i * len_step:i * len_step + len_step],
  109. z[i * len_step:i * len_step + len_step])
  110. plt.title(str(i * len_step))
  111. plt.xlabel('$Bx$', color='g')
  112. plt.ylabel('$By$', color='g')
  113. ax.set_zlabel('$Bz$')
  114. writer.grab_frame()
  115. plt.show()
  116. def Video(x, y, z, len_step):
  117. from matplotlib.animation import FFMpegWriter
  118. metadata = dict(title="Movie")
  119. writer2 = FFMpegWriter(fps=2, metadata=metadata)
  120. fig = plt.figure(figsize=(12, 12), dpi=100)
  121. ax = fig.add_subplot(projection='3d')
  122. with writer2.saving(fig, "Banimate.mp4", 100):
  123. for i in range(100):
  124. ax.clear()
  125. ax.scatter(x[i * len_step:i * len_step + len_step], y[i * len_step:i * len_step + len_step],
  126. z[i * len_step:i * len_step + len_step])
  127. plt.title(str(i * len_step))
  128. plt.xlabel('$Bx$', color='g')
  129. plt.ylabel('$By$', color='g')
  130. ax.set_zlabel('$Bz$')
  131. # ax.set_xlim(min(X), max(X))
  132. # ax.set_ylim(min(Y), max(Y))
  133. # ax.set_zlim(min(Z), max(Z))
  134. writer2.grab_frame()
  135. plt.show()
  136. fig = plt.figure(figsize=plt.figaspect(0.5))
  137. amoung = 3
  138. j = 1
  139. for i in range(24, 33):
  140. ax = fig.add_subplot(amoung, amoung, j, projection='3d')
  141. ax.scatter(x[i * len_step:i * len_step + len_step], y[i * len_step:i * len_step + len_step],
  142. z[i * len_step:i * len_step + len_step], s=0.01)
  143. ax.set_yticklabels([])
  144. ax.set_xticklabels([])
  145. ax.set_zticklabels([])
  146. j += 1
  147. plt.show()