diff --git a/requirements.txt b/requirements.txt index 85fbc96ea..2e5668f0c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -numpy>=1.23 # matplotlib 3.9 requires it +numpy>=1.23 # matplotlib 3.10 requires it scipy>=1.8 # first to allow numpy 1.23; bootstrap needs 1.7 -matplotlib>=3.9.0 # Released May 15th 2024 +matplotlib>=3.10.0 # first with boxplot(orientation=...) netCDF4>=1.6.4 requests pytz diff --git a/rocketpy/plots/monte_carlo_plots.py b/rocketpy/plots/monte_carlo_plots.py index aeb0f2746..8cc1716ea 100644 --- a/rocketpy/plots/monte_carlo_plots.py +++ b/rocketpy/plots/monte_carlo_plots.py @@ -415,8 +415,7 @@ def all(self, keys=None, *, filename=None): ax2 = fig.add_subplot(gs[1]) # Plot boxplot - # TODO: changes vert to orientation="horizontal" when support for Py3.9 ends - ax1.boxplot(self.monte_carlo.results[key], vert=False) + ax1.boxplot(self.monte_carlo.results[key], orientation="horizontal") ax1.set_title(f"Box Plot of {key}") ax1.set_yticks([]) @@ -468,7 +467,7 @@ def plot_comparison(self, other_monte_carlo): # Plot boxplot bp = ax1.boxplot( [other_monte_carlo.results[key], self.monte_carlo.results[key]], - vert=False, + orientation="horizontal", tick_labels=["Other", "Original"], patch_artist=True, ) diff --git a/tests/unit/simulation/test_monte_carlo_plots.py b/tests/unit/simulation/test_monte_carlo_plots.py index 6e049c0fb..d2100f21a 100644 --- a/tests/unit/simulation/test_monte_carlo_plots.py +++ b/tests/unit/simulation/test_monte_carlo_plots.py @@ -1,14 +1,17 @@ -"""Unit tests for the ellipse plots in ``rocketpy.plots.monte_carlo_plots``. +"""Unit tests for the ellipse and box plots in ``rocketpy.plots.monte_carlo_plots``. Background-map fetching is covered separately in ``test_monte_carlo_plots_background.py``. Everything here runs with ``background=None`` so no tile provider is contacted. """ +import warnings from unittest.mock import patch +import matplotlib.pyplot as plt import numpy as np import pytest +from matplotlib import MatplotlibDeprecationWarning from rocketpy.plots.monte_carlo_plots import _MonteCarloPlots from rocketpy.simulation import MonteCarlo @@ -116,3 +119,39 @@ def test_ellipses_comparison_draws_over_an_image(mock_show, square_image): # py other = MockMonteCarlo({**APOGEE, **IMPACT}, filename="other") assert monte_carlo.plots.ellipses_comparison(other, image=square_image) is None + + +def _box_plot_x_range(axes): + """The whiskers of a horizontal box plot span the data along x.""" + x_data = np.concatenate([line.get_xdata() for line in axes.lines]) + return x_data.min(), x_data.max() + + +@patch("matplotlib.pyplot.show") +def test_all_draws_horizontal_box_plots_without_deprecated_arguments(mock_show): # pylint: disable=unused-argument + """``vert`` is deprecated in Matplotlib 3.11 and removed in 3.13 (#1230).""" + monte_carlo = MockMonteCarlo(dict(APOGEE)) + + with warnings.catch_warnings(): + warnings.simplefilter("error", MatplotlibDeprecationWarning) + monte_carlo.plots.all("apogee_x") + + assert _box_plot_x_range(plt.gcf().axes[0]) == (100, 300) + plt.close("all") + + +@patch("matplotlib.pyplot.show") +def test_plot_comparison_draws_horizontal_box_plots_without_deprecated_arguments( # pylint: disable=unused-argument + mock_show, +): + """The comparison box plot takes the same ``orientation`` argument (#1230).""" + monte_carlo = MockMonteCarlo(dict(APOGEE)) + other = MockMonteCarlo(dict(APOGEE), filename="other") + monte_carlo.processed_results = other.processed_results = {"apogee_x": None} + + with warnings.catch_warnings(): + warnings.simplefilter("error", MatplotlibDeprecationWarning) + monte_carlo.plots.plot_comparison(other) + + assert _box_plot_x_range(plt.gcf().axes[0]) == (100, 300) + plt.close("all")