Skip to content

Commit 85af1a9

Browse files
committed
update lagrange_points example
1 parent 42dc6d3 commit 85af1a9

1 file changed

Lines changed: 30 additions & 22 deletions

File tree

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,72 @@
1+
import matplotlib.pyplot as plt
2+
13
from amuse.plot import xlabel, ylabel, effective_iso_potential_plot
24
from amuse.units import units, constants, nbody_system
35
from amuse.community.hermite import Hermite
46
from amuse.datamodel import Particles
57

6-
from matplotlib import pyplot as plt
7-
plt.style.use('../lib/matplotlibrc')
8-
color = plt.rcParams['axes.prop_cycle'].by_key()['color']
98

109
def new_sun_earth_system():
1110
particles = Particles(2)
1211
particles.mass = [1, 0.2] | units.MSun
13-
particles.position = [[0, 0, 0], [1.0, 0, 0]] | units.AU
12+
particles.position = [[0, 0, 0], [1.0, 0, 0]] | units.au
1413
particles.velocity = [0, 0, 0] | units.kms
15-
particles[1].vy = (constants.G * particles.total_mass()
16-
/ particles[1].x).sqrt()
14+
particles[1].vy = (constants.G * particles.total_mass() / particles[1].x).sqrt()
1715
return particles
1816

1917

2018
def setup_gravity_code():
21-
converter = nbody_system.nbody_to_si(1.0 | units.MSun, 1.0 | units.AU)
19+
converter = nbody_system.nbody_to_si(1.0 | units.MSun, 1.0 | units.au)
2220
gravity = Hermite(converter)
2321
gravity.particles.add_particles(new_sun_earth_system())
2422
return gravity
2523

2624

2725
def make_effective_iso_potential_plot(gravity_code):
28-
omega = (constants.G * gravity_code.particles.total_mass()
29-
/ (1.0 | units.AU**3)).sqrt()
26+
omega = (
27+
constants.G * gravity_code.particles.total_mass() / (1.0 | units.au**3)
28+
).sqrt()
3029
center_of_mass = gravity_code.particles.center_of_mass()[:2]
3130

32-
#plt.rcParams.update({'font.size': 30})
3331
figure = plt.figure(figsize=(8, 8))
34-
ax = plt.gca()
32+
ax = figure.add_subplot(1, 1, 1)
3533
ax.get_yaxis().get_major_formatter().set_useOffset(False)
36-
ax.minorticks_on()
34+
ax.minorticks_on()
3735

3836
current_axes = plt.subplot(1, 1, 1)
3937
current_axes.set_aspect("equal", adjustable="box")
4038
lim = 1.7
41-
effective_iso_potential_plot(gravity_code,
42-
omega,
43-
xlim=[-lim, lim] | units.AU,
44-
ylim=[-lim, lim] | units.AU,
45-
center_of_rotation=center_of_mass,
46-
fraction_screen_filled=0.8)
47-
xlabel('x')
48-
ylabel('y')
39+
effective_iso_potential_plot(
40+
gravity_code,
41+
omega,
42+
xlim=[-lim, lim] | units.au,
43+
ylim=[-lim, lim] | units.au,
44+
center_of_rotation=center_of_mass,
45+
fraction_screen_filled=0.8,
46+
)
47+
xlabel("x")
48+
ylabel("y")
4949
plt.text(0.6, -0.06, "$L_1$")
5050
plt.text(1.35, -0.06, "$L_2$")
5151
plt.text(-0.99, -0.06, "$L_3$")
5252
plt.text(0.40, 0.82, "$L_4$")
5353
plt.text(0.40, -0.92, "$L_5$")
5454

55-
save_file = '../figures/lagrange_points.pdf'
55+
save_file = "../figures/lagrange_points.pdf"
5656
plt.savefig(save_file)
5757
print("\nOutput saved in", save_file)
5858
plt.show()
5959

6060

61-
if __name__ == "__main__":
61+
def lagrange_points():
6262
gravity = setup_gravity_code()
6363
make_effective_iso_potential_plot(gravity)
6464
gravity.stop()
65+
66+
67+
def main():
68+
lagrange_points()
69+
70+
71+
if __name__ == "__main__":
72+
main()

0 commit comments

Comments
 (0)