Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion oplot/plot_data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def scatter_and_color_according_to_y(

elif isinstance(y[0], float):
legend = False
cm = plt.cm.get_cmap(cmap_col)
cm = plt.get_cmap(cmap_col)
colors = None
col = 'continuous'
no_tag = True
Expand Down
24 changes: 24 additions & 0 deletions tests/test_plot_data_set.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""Tests for oplot.plot_data_set module"""

import warnings

import pytest
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import MatplotlibDeprecationWarning
from matplotlib.axes import Axes

from oplot.plot_data_set import (
Expand Down Expand Up @@ -112,6 +115,27 @@ def test_scatter_with_float_y(self):
scatter_and_color_according_to_y(X, y, projection='2d', dim_reduct='PCA')
plt.close('all')

def test_scatter_with_float_y_emits_no_deprecation_warning(self):
"""Continuous-y colouring must not rely on deprecated matplotlib APIs.

``matplotlib.cm.get_cmap`` (a.k.a. ``plt.cm.get_cmap``) is deprecated
since matplotlib 3.7 and slated for removal in 3.11, which would turn
the float-``y`` branch into an ``AttributeError``.
"""
np.random.seed(42)
X = np.random.rand(50, 4)
y = np.random.rand(50)
with warnings.catch_warnings(record=True) as recorded:
warnings.simplefilter('always')
scatter_and_color_according_to_y(X, y, projection='2d', dim_reduct='PCA')
plt.close('all')
deprecations = [
str(w.message)
for w in recorded
if issubclass(w.category, MatplotlibDeprecationWarning)
]
assert not deprecations, f'deprecated matplotlib API used: {deprecations}'

def test_scatter_1d(self):
"""Test 1D scatter plot"""
np.random.seed(42)
Expand Down
Loading