Penning Trap Simulation Simulate particle behavior inside a Penning Trap

Loading...
Searching...
No Matches
plot_phase_space.py
1 import matplotlib.pyplot as plt
2 import numpy as np
3
4 def main():
5 directories = {
6 "output/simulate_2_particles/no_interaction/",
7 "output/simulate_2_particles/with_interaction/",
8 }
9 titles = {
10 "particles without interaction",
11 "particles with interaction"
12 }
13 files = [
14 "particle_0_r.txt",
15 "particle_0_v.txt",
16 "particle_1_r.txt",
17 "particle_1_v.txt",
18 ]
19 labels = [
20 r"particle 1 r",
21 r"particle 1 v",
22 r"particle 2 r",
23 r"particle 2 v",
24 ]
25 colors = [
26 "lightskyblue",
27 "deepskyblue",
28 "salmon",
29 "tomato",
30 ]
31 fig1, axs1 = plt.subplots(2,1)
32 fig2, axs2 = plt.subplots(2,1)
33 for i, (dir, title) in enumerate(zip(directories, titles)):
34 for label, color, file in zip(labels, colors, files):
35 with open(dir+file) as f:
36 lines = f.readlines()
37 t = np.linspace(0, 50, len(lines))
38 r = np.array([list(map(float, line.strip().split(","))) for line in lines])
39 axs1[i].plot(t, r[:,0], label=label, color=color)
40 axs2[i].plot(t, r[:,2], label=label, color=color)
41
42 axs1[i].set(xlabel=r"t $(\mu s)$", ylabel = r"z $(\mu m)$")
43
44 axs1[i].legend()
45 axs1[i].set_title(title)
46
47 # plt.show()
48 fig1.savefig("../latex/images/phase_space_2_particles_x.pdf")
49 fig2.savefig("../latex/images/phase_space_2_particles_z.pdf")
50
51
52 if __name__ == "__main__":
53 main()