diff --git a/CHANGELOG.md b/CHANGELOG.md index 602739494..a578ede83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,7 +46,7 @@ straightforward as possible. - ENH Precalculate Barometric Height [#511](https://github.com/RocketPy-Team/RocketPy/pull/511) - MNT: Encapsulate quaternion conversions [#537](https://github.com/RocketPy-Team/RocketPy/pull/537) - MNT: improve the low pass filter and document an example [#538](https://github.com/RocketPy-Team/RocketPy/pull/538) - +- ENH: Plotting both power on and off drag curves in a single plot [#547](https://github.com/RocketPy-Team/RocketPy/pull/547) ### Fixed @@ -54,7 +54,7 @@ straightforward as possible. - BUG: fin_flutter_analysis doesn't find any fin set [#510](https://github.com/RocketPy-Team/RocketPy/pull/510) - FIX: EmptyMotor is breaking the Rocket.draw() method [#516](https://github.com/RocketPy-Team/RocketPy/pull/516) - BUG: 3D trajectory plot not labeling axes [#533](https://github.com/RocketPy-Team/RocketPy/pull/533) -- + ## [v1.1.5] - 2024-01-21 diff --git a/rocketpy/plots/rocket_plots.py b/rocketpy/plots/rocket_plots.py index c3fb998f6..56b57fdd1 100644 --- a/rocketpy/plots/rocket_plots.py +++ b/rocketpy/plots/rocket_plots.py @@ -1,5 +1,6 @@ import matplotlib.pyplot as plt import numpy as np +import warnings from rocketpy.motors import EmptyMotor, HybridMotor, LiquidMotor, SolidMotor from rocketpy.rocket.aero_surface import Fins, NoseCone, Tail @@ -94,6 +95,13 @@ def power_on_drag(self): None """ + warnings.warn( + "The method 'power_on_drag' is deprecated as of version " + + "1.2 and will be removed in version 1.4 " + + "Use 'plots.drag_curves' instead.", + DeprecationWarning, + ) + self.rocket.power_on_drag() return None @@ -106,10 +114,44 @@ def power_off_drag(self): None """ + warnings.warn( + "The method 'power_off_drag' is deprecated as of version " + + "1.2 and will be removed in version 1.4 " + + "Use 'plots.drag_curves' instead.", + DeprecationWarning, + ) + self.rocket.power_off_drag() return None + def drag_curves(self): + """Plots power off and on drag curves of the rocket as a function of time. + + Returns + ------- + None + """ + + x_power_drag_off = self.rocket.power_off_drag.x_array + y_power_drag_off = self.rocket.power_off_drag.y_array + x_power_drag_on = self.rocket.power_on_drag.x_array + y_power_drag_on = self.rocket.power_on_drag.y_array + + fig, ax = plt.subplots() + ax.plot(x_power_drag_on, y_power_drag_on, label="Power on Drag") + ax.plot( + x_power_drag_off, y_power_drag_off, label="Power off Drag", linestyle="--" + ) + + ax.set_title("Drag Curves") + ax.set_ylabel("Drag Coefficient") + ax.set_xlabel("Mach") + ax.axvspan(0.8, 1.2, alpha=0.3, color="gray", label="Transonic Region") + ax.legend(loc="best", shadow=True) + plt.grid(True) + plt.show() + def thrust_to_weight(self): """Plots the motor thrust force divided by rocket weight as a function of time. @@ -524,8 +566,7 @@ def all(self): # Drag Plots print("Drag Plots") print("-" * 20) # Separator for Drag Plots - self.power_on_drag() - self.power_off_drag() + self.drag_curves() # Stability Plots print("\nStability Plots")