-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotting.py
125 lines (96 loc) · 5.44 KB
/
plotting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
class Plot:
def plt():
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import config
o=config.Init
fig = plt.figure()
ax = plt.axes(projection='3d')
# postions of the Earth in x,y, and z planes
object2_x = o.positions2[:,0]
object2_y = o.positions2[:,1]
object2_z = o.positions2[:,2]
# postions of the Sun in x,y, and z planes
object1_x = o.positions1[:,0]
object1_y = o.positions1[:,1]
object1_z = o.positions1[:,2]
# postions of the Venus in x,y, and z planes
object3_x = o.positions3[:,0]
object3_y = o.positions3[:,1]
object3_z = o.positions3[:,2]
# postions of the Mars in x,y, and z planes
object4_x = o.positions4[:,0]
object4_y = o.positions4[:,1]
object4_z = o.positions4[:,2]
# postions of the Jupiter in x,y, and z planes
object5_x = o.positions5[:,0]
object5_y = o.positions5[:,1]
object5_z = o.positions5[:,2]
# postions of the Saturn in x,y, and z planes
object6_x = o.positions6[:,0]
object6_y = o.positions6[:,1]
object6_z = o.positions6[:,2]
# postions of the Uranus in x,y, and z planes
object7_x = o.positions7[:,0]
object7_y = o.positions7[:,1]
object7_z = o.positions7[:,2]
# postions of the Neptune in x,y, and z planes
object8_x = o.positions8[:,0]
object8_y = o.positions8[:,1]
object8_z = o.positions8[:,2]
# postions of the Pluto in x,y, and z planes
object9_x = o.positions9[:,0]
object9_y = o.positions9[:,1]
object9_z = o.positions9[:,2]
# Create a figure and 3D axis
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
fig, ax = plt.subplots(figsize=(10, 8), subplot_kw={'projection': '3d'})
# Initialize empty lines
object1_line, = ax.plot([], [], 'k.-', label='Sun', color='black',linewidth=0.5, markersize=11, markevery=[-1],markeredgecolor='magenta', markerfacecolor='Violet')
object2_line, = ax.plot([], [], 'k.-', label='Earth', color='indigo',linewidth=0.5, markersize=10, markevery=[-1],markeredgecolor='Blue', markerfacecolor='Blue')
object3_line, = ax.plot([], [], 'k.-', label='Venus', color='black',linewidth=0.5, markersize=8, markevery=[-1],markeredgecolor='green', markerfacecolor='green')
object4_line, = ax.plot([], [], 'k.-', label='Mars', color='indigo',linewidth=0.5, markersize=5, markevery=[-1],markeredgecolor='purple', markerfacecolor='purple')
object5_line, = ax.plot([], [], 'k.-', label='Jupiter', color='black',linewidth=0.5, markersize=20, markevery=[-1],markeredgecolor='white', markerfacecolor='brown')
object6_line, = ax.plot([], [], 'k.-', label='Saturn', color='indigo',linewidth=0.5, markersize=16, markevery=[-1],markeredgecolor='Brown', markerfacecolor='brown')
object7_line, = ax.plot([], [], 'k.-', label='Uranus', color='black',linewidth=0.5, markersize=14, markevery=[-1],markeredgecolor='grey', markerfacecolor='grey')
object8_line, = ax.plot([], [], 'k.-', label='Neptune', color='indigo',linewidth=0.5, markersize=12, markevery=[-1],markeredgecolor='yellow', markerfacecolor='yellow')
object9_line, = ax.plot([], [], 'k.-', label='Pluto', color='indigo',linewidth=0.5, markersize=10, markevery=[-1],markeredgecolor='red', markerfacecolor='red')
ax.set_xlim3d([-2e11,50e11])
ax.set_ylim3d([-2e11,50e11])
ax.set_zlim3d([-2e11,2e4])
# Animation update function
def update(frame):
# Update the data of each line
object1_line.set_data(object1_x[:frame+1], object1_y[:frame+1])
object1_line.set_3d_properties(object1_z[:frame+1])
object2_line.set_data(object2_x[:frame+1], object2_y[:frame+1])
object2_line.set_3d_properties(object2_z[:frame+1])
object3_line.set_data(object3_x[:frame+1], object3_y[:frame+1])
object3_line.set_3d_properties(object3_z[:frame+1])
object4_line.set_data(object4_x[:frame+1], object4_y[:frame+1])
object4_line.set_3d_properties(object4_z[:frame+1])
object5_line.set_data(object5_x[:frame+1], object5_y[:frame+1])
object5_line.set_3d_properties(object5_z[:frame+1])
object6_line.set_data(object6_x[:frame+1], object6_y[:frame+1])
object6_line.set_3d_properties(object6_z[:frame+1])
object7_line.set_data(object7_x[:frame+1], object7_y[:frame+1])
object7_line.set_3d_properties(object7_z[:frame+1])
object8_line.set_data(object8_x[:frame+1], object8_y[:frame+1])
object8_line.set_3d_properties(object8_z[:frame+1])
object9_line.set_data(object9_x[:frame+1], object9_y[:frame+1])
object9_line.set_3d_properties(object9_z[:frame+1])
# Animate the plot
anim = FuncAnimation(fig, update, frames=len(object1_x), interval=1, repeat=True)
# Set plot properties
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_zlabel('Z-axis')
ax.set_title('Many body simulation - Solar system')
ax.legend()
fig_manager = plt.get_current_fig_manager()
fig_manager.full_screen_toggle()
#anim.save('Solar_system.gif', writer='pillow') # in order to save the animation to your computer...
# Display the animation
plt.show()