Penning Trap Simulation
Simulate particle behavior inside a Penning Trap
Loading...
Searching...
No Matches
plot_3d.py
1import matplotlib.pyplot as plt
2import numpy as np
3
4def main():
5 files = [
6 "output/simulate_2_particles/no_interaction/particle_0_r.txt",
7 "output/simulate_2_particles/no_interaction/particle_1_r.txt",
8 "output/simulate_2_particles/with_interaction/particle_0_r.txt",
9 "output/simulate_2_particles/with_interaction/particle_1_r.txt"
10 ]
11 labels = [
12 "particle 1 no interaction",
13 "particle 2 no interaction",
14 "particle 1 with interaction",
15 "particle 2 with interaction",
16 ]
17 colors = [
18 "lightskyblue",
19 "deepskyblue",
20 "salmon",
21 "darkred"
22 ]
23 ax = plt.figure().add_subplot(projection="3d")
24 for label, color, file in zip(labels, colors, files):
25 with open(file) as f:
26 lines = f.readlines()
27 t = np.linspace(0, 50, len(lines))
28 r = np.array([list(map(float, line.strip().split(","))) for line in lines])
29 ax.plot(r[:,0], r[:,1], r[:,2], label=label, color=color)
30
31 ax.set_xlabel(r"x $(\mu m)$")
32 ax.set_ylabel(r"y $(\mu m)$")
33 ax.set_zlabel(r"z $(\mu m)$")
34 plt.title(r"2 particles with and without interactions.")
35 plt.legend()
36 plt.savefig("../latex/images/3d_plot.pdf")
37
38
39if __name__ == "__main__":
40 main()