|
| 1 | +import matplotlib.pyplot as plt |
| 2 | +import numpy as np |
| 3 | +import argparse |
| 4 | + |
| 5 | +def plot_orbit(positions, title="Orbital Trajectory", save_path=None): |
| 6 | + """ |
| 7 | + Plots two orbital trajectories given a list of 3D positions. |
| 8 | +
|
| 9 | + Parameters: |
| 10 | + positions: A list of 3d particle trajectories (x, y, z) positions for N times, as a list of M ndarrays of shape (N, 3). |
| 11 | + title (str): The title of the plot. |
| 12 | + save_path (str): If provided, the plot will be saved to this path. |
| 13 | + """ |
| 14 | + |
| 15 | + # Create a 3D plot |
| 16 | + fig = plt.figure() |
| 17 | + ax = fig.add_subplot(111, projection='3d') |
| 18 | + |
| 19 | + # Plot the trajectories |
| 20 | + for n in range(len(positions)): |
| 21 | + ax.plot(positions[n][:, 0], positions[n][:, 1], positions[n][:, 2], '-') |
| 22 | + |
| 23 | + # Set labels and title |
| 24 | + ax.set_xlabel('X Position') |
| 25 | + ax.set_ylabel('Y Position') |
| 26 | + ax.set_zlabel('Z Position') |
| 27 | + ax.set_title(title) |
| 28 | + |
| 29 | + # Show grid |
| 30 | + ax.grid(True) |
| 31 | + |
| 32 | + # Save or show the plot |
| 33 | + if save_path: |
| 34 | + plt.savefig(save_path) |
| 35 | + else: |
| 36 | + plt.show() |
| 37 | + |
| 38 | + |
| 39 | +if __name__ == "__main__": |
| 40 | + parser = argparse.ArgumentParser(description="Plot orbital trajectory from 3D positions.") |
| 41 | + parser.add_argument('--input', type=str, |
| 42 | + default='ORBTRACE.run0', |
| 43 | + help="Path to the input file containing 3D positions (one per line as x,y,z).") |
| 44 | + |
| 45 | + args = parser.parse_args() |
| 46 | + |
| 47 | + data = np.loadtxt(args.input) |
| 48 | + |
| 49 | + pos = [] |
| 50 | + pos.append(data[:, 1:4]) # First object positions |
| 51 | + pos.append(data[:, 7:10]) # Second object positions |
| 52 | + pos.append(data[:, 13:16]) # Third object positions |
| 53 | + pos.append(data[:, 19:22]) # Fourth object positions |
| 54 | + pos.append(data[:, 25:28]) # Fifth object positions |
| 55 | + |
| 56 | + plot_orbit(pos, title="Selected disk orbits") |
0 commit comments