From e4ce81d75dc509557878eda5d7900fe0cf678f45 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Sun, 16 Jun 2024 19:48:54 -0300 Subject: [PATCH] MNT: Update flight_plots.py to set consistent limits for x and y axes --- rocketpy/plots/flight_plots.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rocketpy/plots/flight_plots.py b/rocketpy/plots/flight_plots.py index 21266a1f3..1209b4cd6 100644 --- a/rocketpy/plots/flight_plots.py +++ b/rocketpy/plots/flight_plots.py @@ -66,6 +66,14 @@ def trajectory_3d(self): min_x = min(self.flight.x[:, 1]) max_y = max(self.flight.y[:, 1]) min_y = min(self.flight.y[:, 1]) + min_xy = min(min_x, min_y) + max_xy = max(max_x, max_y) + + # avoids errors when x_lim and y_lim are the same + if abs(min_z - max_z) < 1e-5: + max_z += 1 + if abs(min_xy - max_xy) < 1e-5: + max_xy += 1 _ = plt.figure(figsize=(9, 9)) ax1 = plt.subplot(111, projection="3d") @@ -109,8 +117,8 @@ def trajectory_3d(self): ax1.set_ylabel("Y - North (m)") ax1.set_zlabel("Z - Altitude Above Ground Level (m)") ax1.set_title("Flight Trajectory") - ax1.set_xlim(min_x, max_x) - ax1.set_ylim(min_y, max_y) + ax1.set_xlim(min_xy, max_xy) + ax1.set_ylim(min_xy, max_xy) ax1.set_zlim(min_z, max_z) ax1.view_init(15, 45) ax1.set_box_aspect(None, zoom=0.95) # 95% for label adjustment