Penning Trap Simulation
Simulate particle behavior inside a Penning Trap
Loading...
Searching...
No Matches
plot_phase_space.py
Go to the documentation of this file.
1
12
13import matplotlib.pyplot as plt
14import numpy as np
15import seaborn as sns
16
17sns.set_theme()
18params = {
19 "font.family": "Serif",
20 "font.serif": "Roman",
21 "text.usetex": True,
22 "axes.titlesize": "large",
23 "axes.labelsize": "large",
24 "xtick.labelsize": "large",
25 "ytick.labelsize": "large",
26 "legend.fontsize": "medium",
27}
28plt.rcParams.update(params)
29
30
31def main():
32 directories = [
33 "output/simulate_2_particles/no_interaction/",
34 "output/simulate_2_particles/with_interaction/",
35 ]
36 files = [
37 "particle_0",
38 "particle_1",
39 ]
40 labels = [r"$p_1$", r"$p_2$"]
41 output = [
42 "../latex/images/phase_space_no_interaction",
43 "../latex/images/phase_space_interaction",
44 ]
45 colors = [
46 "seagreen",
47 "darkred",
48 ]
49
50 for i, dir in enumerate(directories):
51 fig1, axs1 = plt.subplots(sharex=True)
52 fig2, axs2 = plt.subplots(sharex=True)
53 for j, (file, label, color) in enumerate(zip(files, labels, colors)):
54 r = []
55 v = []
56 with open(dir + file + "_r.txt") as f:
57 lines = f.readlines()
58 r = np.array(
59 [list(map(float, line.strip().split(","))) for line in lines]
60 )
61
62 with open(dir + file + "_v.txt") as f:
63 lines = f.readlines()
64 v = np.array(
65 [list(map(float, line.strip().split(","))) for line in lines]
66 )
67 axs1.plot(r[:, 0], v[:, 0], label=label, color=color)
68 axs1.plot(r[0,0], v[0,0], "ko")
69 axs2.plot(r[:, 2], v[:, 2], label=label, color=color)
70 axs2.plot(r[0,2], v[0,2], "ko")
71 axs1.axis("equal")
72 axs2.axis("equal")
73
74 axs1.set(xlabel=r"$x (\mu m)$", ylabel=r"$v_x (\mu m / \mu s)$")
75 axs2.set(xlabel=r"$z (\mu m)$", ylabel=r"$v_z (\mu m / \mu s)$")
76
77 axs1.legend(loc="upper right")
78 axs2.legend(loc="upper right")
79
80 fig1.savefig(f"{output[i]}_x.pdf", bbox_inches="tight")
81 fig2.savefig(f"{output[i]}_z.pdf", bbox_inches="tight")
82 # plt.show()
83
84
85if __name__ == "__main__":
86 main()