From 52ead63d7cedc955cafd25ea01ab263d465ecda9 Mon Sep 17 00:00:00 2001 From: vovw Date: Sun, 14 Sep 2025 22:06:45 +0530 Subject: [PATCH] Fix matplotlib colormap deprecation warnings for 3.11 compatibility - Replace matplotlib.cm.get_cmap() with matplotlib.colormaps.get_cmap() - Replace plt.get_cmap() with matplotlib.colormaps.get_cmap() - Update cebra/integrations/plotly.py, matplotlib.py, and tests/test_plotly.py - Remove matplotlib<3.11 version pin from setup.cfg - Ensures future compatibility with matplotlib 3.11+ releases Fixes #240 --- cebra/integrations/matplotlib.py | 2 +- cebra/integrations/plotly.py | 2 +- setup.cfg | 4 +--- tests/test_plotly.py | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/cebra/integrations/matplotlib.py b/cebra/integrations/matplotlib.py index c2696d4a..844844fd 100644 --- a/cebra/integrations/matplotlib.py +++ b/cebra/integrations/matplotlib.py @@ -1235,7 +1235,7 @@ def compare_models( # check the color of the traces if color is None: - cebra_map = plt.get_cmap(cmap) + cebra_map = matplotlib.colormaps.get_cmap(cmap) colors = matplotlib.colors.ListedColormap( cebra_map.resampled(n_models)(np.arange(n_models))).colors else: diff --git a/cebra/integrations/plotly.py b/cebra/integrations/plotly.py index 2cfc5ec9..af8719fd 100644 --- a/cebra/integrations/plotly.py +++ b/cebra/integrations/plotly.py @@ -87,7 +87,7 @@ def _define_colorscale(self, cmap: str): Returns: colorscale: List of scaled colors to plot the embeddings """ - colorscale = _convert_cmap2colorscale(matplotlib.cm.get_cmap(cmap)) + colorscale = _convert_cmap2colorscale(matplotlib.colormaps.get_cmap(cmap)) return colorscale diff --git a/setup.cfg b/setup.cfg index 7faff998..0bfa5f84 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,9 +39,7 @@ install_requires = scipy torch>=2.4.0 tqdm - # NOTE(stes): Remove pin once https://github.com/AdaptiveMotorControlLab/CEBRA/issues/240 - # is resolved. - matplotlib<3.11 + matplotlib requests [options.extras_require] diff --git a/tests/test_plotly.py b/tests/test_plotly.py index 187d234c..b1a86b67 100644 --- a/tests/test_plotly.py +++ b/tests/test_plotly.py @@ -31,7 +31,7 @@ @pytest.mark.parametrize("cmap", ["viridis", "plasma", "inferno", "magma"]) def test_colorscale(cmap): - cmap = matplotlib.cm.get_cmap(cmap) + cmap = matplotlib.colormaps.get_cmap(cmap) colorscale = cebra_plotly._convert_cmap2colorscale(cmap) assert isinstance(colorscale, list)