From b9fe81ee115f139ab5b615e775bf97222e995190 Mon Sep 17 00:00:00 2001 From: KCollins Date: Sun, 1 Nov 2026 13:19:13 -0500 Subject: [PATCH 1/2] Removed N parameter from colors.ListedColorMap instantiations. Addresses #122 --- cmocean/cm.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmocean/cm.py b/cmocean/cm.py index 7ffe563..6c03393 100644 --- a/cmocean/cm.py +++ b/cmocean/cm.py @@ -53,11 +53,11 @@ def _register_cmap(cmap, *, name): rgb_with_alpha = np.zeros((rgb.shape[0],4)) rgb_with_alpha[:,:3] = rgb rgb_with_alpha[:,3] = 1. #set alpha channel to 1 - reg_map = colors.ListedColormap(rgb_with_alpha, N=rgb.shape[0]) + reg_map = colors.ListedColormap(rgb_with_alpha) _register_cmap(reg_map, name=f'cmo.{cmapname}') # Register the reversed map - reg_map_r = colors.ListedColormap(rgb_with_alpha[::-1,:], N=rgb.shape[0]) + reg_map_r = colors.ListedColormap(rgb_with_alpha[::-1,:]) _register_cmap(reg_map_r, name=f'cmo.{cmapname}_r') # Load inverted cmaps @@ -71,9 +71,9 @@ def _register_cmap(cmap, *, name): rgb_with_alpha[:,3] = 1. #set alpha channel to 1 # Register inverted cmaps - reg_map_i = colors.ListedColormap(rgb_with_alpha, N=rgb_i.shape[0]) + reg_map_i = colors.ListedColormap(rgb_with_alpha) _register_cmap(reg_map_i, name=f'cmo.{cmapname}_i') - reg_map_r_i = colors.ListedColormap(rgb_with_alpha[::-1,:], N=rgb_i.shape[0]) + reg_map_r_i = colors.ListedColormap(rgb_with_alpha[::-1,:]) _register_cmap(reg_map_r_i, name=f'cmo.{cmapname}_r_i') # order shouldn't matter From d91d235fbdca054e9a88e9aa6d5200e80b516c32 Mon Sep 17 00:00:00 2001 From: KCollins Date: Sun, 1 Nov 2026 13:27:09 -0500 Subject: [PATCH 2/2] Added ListedColormap to tests. --- tests/test_cmocean.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cmocean.py b/tests/test_cmocean.py index b6f7c49..d508b14 100644 --- a/tests/test_cmocean.py +++ b/tests/test_cmocean.py @@ -16,7 +16,7 @@ def test_cmap_import(): # Loop through all methods in cmocean. for name, cmap in vars(cm).items(): # See if it is a colormap. - if isinstance(cmap, matplotlib.colors.LinearSegmentedColormap): + if isinstance(cmap, (matplotlib.colors.LinearSegmentedColormap, matplotlib.colors.ListedColormap)): print(name) x = np.linspace(0, 10) X, _ = np.meshgrid(x, x)