|
| 1 | +import matplotlib.pyplot as plt |
| 2 | + |
1 | 3 | from amuse.plot import xlabel, ylabel, effective_iso_potential_plot |
2 | 4 | from amuse.units import units, constants, nbody_system |
3 | 5 | from amuse.community.hermite import Hermite |
4 | 6 | from amuse.datamodel import Particles |
5 | 7 |
|
6 | | -from matplotlib import pyplot as plt |
7 | | -plt.style.use('../lib/matplotlibrc') |
8 | | -color = plt.rcParams['axes.prop_cycle'].by_key()['color'] |
9 | 8 |
|
10 | 9 | def new_sun_earth_system(): |
11 | 10 | particles = Particles(2) |
12 | 11 | 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 |
14 | 13 | 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() |
17 | 15 | return particles |
18 | 16 |
|
19 | 17 |
|
20 | 18 | 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) |
22 | 20 | gravity = Hermite(converter) |
23 | 21 | gravity.particles.add_particles(new_sun_earth_system()) |
24 | 22 | return gravity |
25 | 23 |
|
26 | 24 |
|
27 | 25 | 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() |
30 | 29 | center_of_mass = gravity_code.particles.center_of_mass()[:2] |
31 | 30 |
|
32 | | - #plt.rcParams.update({'font.size': 30}) |
33 | 31 | figure = plt.figure(figsize=(8, 8)) |
34 | | - ax = plt.gca() |
| 32 | + ax = figure.add_subplot(1, 1, 1) |
35 | 33 | ax.get_yaxis().get_major_formatter().set_useOffset(False) |
36 | | - ax.minorticks_on() |
| 34 | + ax.minorticks_on() |
37 | 35 |
|
38 | 36 | current_axes = plt.subplot(1, 1, 1) |
39 | 37 | current_axes.set_aspect("equal", adjustable="box") |
40 | 38 | 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") |
49 | 49 | plt.text(0.6, -0.06, "$L_1$") |
50 | 50 | plt.text(1.35, -0.06, "$L_2$") |
51 | 51 | plt.text(-0.99, -0.06, "$L_3$") |
52 | 52 | plt.text(0.40, 0.82, "$L_4$") |
53 | 53 | plt.text(0.40, -0.92, "$L_5$") |
54 | 54 |
|
55 | | - save_file = '../figures/lagrange_points.pdf' |
| 55 | + save_file = "../figures/lagrange_points.pdf" |
56 | 56 | plt.savefig(save_file) |
57 | 57 | print("\nOutput saved in", save_file) |
58 | 58 | plt.show() |
59 | 59 |
|
60 | 60 |
|
61 | | -if __name__ == "__main__": |
| 61 | +def lagrange_points(): |
62 | 62 | gravity = setup_gravity_code() |
63 | 63 | make_effective_iso_potential_plot(gravity) |
64 | 64 | gravity.stop() |
| 65 | + |
| 66 | + |
| 67 | +def main(): |
| 68 | + lagrange_points() |
| 69 | + |
| 70 | + |
| 71 | +if __name__ == "__main__": |
| 72 | + main() |
0 commit comments