From 2afb4a583b88bdc2b27824d824980a7dcab6fc6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Sat, 16 Dec 2023 19:20:44 +0100 Subject: [PATCH] MNT: fix deprecation warnings from matplotlib --- README.rst | 3 +- cmasher/cli_tools.py | 3 +- cmasher/colormaps/amber/amber.py | 6 ++-- cmasher/colormaps/amethyst/amethyst.py | 6 ++-- cmasher/colormaps/apple/apple.py | 6 ++-- cmasher/colormaps/arctic/arctic.py | 6 ++-- cmasher/colormaps/bubblegum/bubblegum.py | 6 ++-- cmasher/colormaps/chroma/chroma.py | 6 ++-- cmasher/colormaps/copper/copper.py | 10 +++--- cmasher/colormaps/cosmic/cosmic.py | 6 ++-- cmasher/colormaps/dusk/dusk.py | 6 ++-- cmasher/colormaps/eclipse/eclipse.py | 6 ++-- cmasher/colormaps/ember/ember.py | 6 ++-- cmasher/colormaps/emerald/emerald.py | 6 ++-- cmasher/colormaps/emergency/emergency.py | 10 +++--- cmasher/colormaps/fall/fall.py | 6 ++-- cmasher/colormaps/flamingo/flamingo.py | 6 ++-- cmasher/colormaps/freeze/freeze.py | 6 ++-- cmasher/colormaps/fusion/fusion.py | 6 ++-- cmasher/colormaps/gem/gem.py | 6 ++-- cmasher/colormaps/ghostlight/ghostlight.py | 6 ++-- cmasher/colormaps/gothic/gothic.py | 6 ++-- cmasher/colormaps/guppy/guppy.py | 6 ++-- cmasher/colormaps/holly/holly.py | 6 ++-- cmasher/colormaps/horizon/horizon.py | 6 ++-- cmasher/colormaps/iceburn/iceburn.py | 6 ++-- cmasher/colormaps/infinity/infinity.py | 10 +++--- cmasher/colormaps/jungle/jungle.py | 6 ++-- cmasher/colormaps/lavender/lavender.py | 6 ++-- cmasher/colormaps/lilac/lilac.py | 6 ++-- cmasher/colormaps/neon/neon.py | 6 ++-- cmasher/colormaps/neutral/neutral.py | 6 ++-- cmasher/colormaps/nuclear/nuclear.py | 6 ++-- cmasher/colormaps/ocean/ocean.py | 6 ++-- cmasher/colormaps/pepper/pepper.py | 6 ++-- cmasher/colormaps/pride/pride.py | 6 ++-- cmasher/colormaps/prinsenvlag/prinsenvlag.py | 6 ++-- cmasher/colormaps/rainforest/rainforest.py | 6 ++-- cmasher/colormaps/redshift/redshift.py | 6 ++-- cmasher/colormaps/sapphire/sapphire.py | 6 ++-- cmasher/colormaps/savanna/savanna.py | 6 ++-- cmasher/colormaps/seasons/seasons.py | 10 +++--- cmasher/colormaps/seaweed/seaweed.py | 6 ++-- cmasher/colormaps/sepia/sepia.py | 6 ++-- cmasher/colormaps/sunburst/sunburst.py | 6 ++-- cmasher/colormaps/swamp/swamp.py | 6 ++-- cmasher/colormaps/torch/torch.py | 6 ++-- cmasher/colormaps/toxic/toxic.py | 6 ++-- cmasher/colormaps/tree/tree.py | 6 ++-- cmasher/colormaps/tropical/tropical.py | 6 ++-- cmasher/colormaps/viola/viola.py | 6 ++-- cmasher/colormaps/voltage/voltage.py | 6 ++-- cmasher/colormaps/waterlily/waterlily.py | 6 ++-- cmasher/colormaps/watermelon/watermelon.py | 6 ++-- cmasher/colormaps/wildfire/wildfire.py | 6 ++-- cmasher/tests/test_utils.py | 16 +++++----- cmasher/utils.py | 33 ++++++++++---------- 57 files changed, 195 insertions(+), 194 deletions(-) diff --git a/README.rst b/README.rst index e60e1941..8d252e17 100644 --- a/README.rst +++ b/README.rst @@ -73,12 +73,13 @@ So, for example, if one were to use the *rainforest* colormap, this could be don import cmasher as cmr # Import packages for plotting + import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np # Access rainforest colormap through CMasher or MPL cmap = cmr.rainforest # CMasher - cmap = plt.get_cmap('cmr.rainforest') # MPL + cmap = mpl.colormaps['cmr.rainforest'] # MPL # Generate some data to plot x = np.random.rand(100) diff --git a/cmasher/cli_tools.py b/cmasher/cli_tools.py index 652dc203..34ad7682 100644 --- a/cmasher/cli_tools.py +++ b/cmasher/cli_tools.py @@ -10,7 +10,6 @@ # Package imports import matplotlib as mpl import numpy as np -from matplotlib import cm as mplcm import cmasher as cmr @@ -240,7 +239,7 @@ def cli_lang_usage_r(): def get_cmap(cmap): # Try to obtain the colormap from MPL try: - cmap = mplcm.get_cmap(cmap) + cmap = mpl.colormaps.get_cmap(cmap) # If this does not work, try to expand given cmap in setuptools-style except ValueError: diff --git a/cmasher/colormaps/amber/amber.py b/cmasher/colormaps/amber/amber.py index c7265485..0b247a78 100644 --- a/cmasher/colormaps/amber/amber.py +++ b/cmasher/colormaps/amber/amber.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/amethyst/amethyst.py b/cmasher/colormaps/amethyst/amethyst.py index 4f9f9072..27f373bb 100644 --- a/cmasher/colormaps/amethyst/amethyst.py +++ b/cmasher/colormaps/amethyst/amethyst.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/apple/apple.py b/cmasher/colormaps/apple/apple.py index cf09087f..9bc4da8e 100644 --- a/cmasher/colormaps/apple/apple.py +++ b/cmasher/colormaps/apple/apple.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/arctic/arctic.py b/cmasher/colormaps/arctic/arctic.py index f31b331c..2a6de9c4 100644 --- a/cmasher/colormaps/arctic/arctic.py +++ b/cmasher/colormaps/arctic/arctic.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/bubblegum/bubblegum.py b/cmasher/colormaps/bubblegum/bubblegum.py index 59117fae..6ac57389 100644 --- a/cmasher/colormaps/bubblegum/bubblegum.py +++ b/cmasher/colormaps/bubblegum/bubblegum.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/chroma/chroma.py b/cmasher/colormaps/chroma/chroma.py index b75cd94f..c8241424 100644 --- a/cmasher/colormaps/chroma/chroma.py +++ b/cmasher/colormaps/chroma/chroma.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/copper/copper.py b/cmasher/colormaps/copper/copper.py index 5885ca44..ff500518 100644 --- a/cmasher/colormaps/copper/copper.py +++ b/cmasher/colormaps/copper/copper.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -536,8 +536,8 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) # Shift the entire colormap by half of its length cm_data_s = list(cm_data[255:]) @@ -548,5 +548,5 @@ cmap_s_r = cmap_s.reversed() # Register shifted versions in MPL as well -register_cmap(cmap=cmap_s) -register_cmap(cmap=cmap_s_r) +mpl.colormaps.register(cmap=cmap_s) +mpl.colormaps.register(cmap=cmap_s_r) diff --git a/cmasher/colormaps/cosmic/cosmic.py b/cmasher/colormaps/cosmic/cosmic.py index 56ecf5e9..4b9d4710 100644 --- a/cmasher/colormaps/cosmic/cosmic.py +++ b/cmasher/colormaps/cosmic/cosmic.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/dusk/dusk.py b/cmasher/colormaps/dusk/dusk.py index 489399f8..68f13682 100644 --- a/cmasher/colormaps/dusk/dusk.py +++ b/cmasher/colormaps/dusk/dusk.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/eclipse/eclipse.py b/cmasher/colormaps/eclipse/eclipse.py index 339faeeb..7bdf4b2e 100644 --- a/cmasher/colormaps/eclipse/eclipse.py +++ b/cmasher/colormaps/eclipse/eclipse.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/ember/ember.py b/cmasher/colormaps/ember/ember.py index 99ece351..1a729389 100644 --- a/cmasher/colormaps/ember/ember.py +++ b/cmasher/colormaps/ember/ember.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/emerald/emerald.py b/cmasher/colormaps/emerald/emerald.py index a1825e76..9294ffc2 100644 --- a/cmasher/colormaps/emerald/emerald.py +++ b/cmasher/colormaps/emerald/emerald.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/emergency/emergency.py b/cmasher/colormaps/emergency/emergency.py index f560dda0..39464549 100644 --- a/cmasher/colormaps/emergency/emergency.py +++ b/cmasher/colormaps/emergency/emergency.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -536,8 +536,8 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) # Determine central value index of the colormap idx = len(cm_data) // 2 @@ -551,5 +551,5 @@ cmap_s_r = cmap_s.reversed() # Register shifted versions in MPL as well -register_cmap(cmap=cmap_s) -register_cmap(cmap=cmap_s_r) +mpl.colormaps.register(cmap=cmap_s) +mpl.colormaps.register(cmap=cmap_s_r) diff --git a/cmasher/colormaps/fall/fall.py b/cmasher/colormaps/fall/fall.py index c37737d7..1abb142d 100644 --- a/cmasher/colormaps/fall/fall.py +++ b/cmasher/colormaps/fall/fall.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/flamingo/flamingo.py b/cmasher/colormaps/flamingo/flamingo.py index ae7ac2ac..003ff15a 100644 --- a/cmasher/colormaps/flamingo/flamingo.py +++ b/cmasher/colormaps/flamingo/flamingo.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/freeze/freeze.py b/cmasher/colormaps/freeze/freeze.py index 75cbce7f..b8d56f45 100644 --- a/cmasher/colormaps/freeze/freeze.py +++ b/cmasher/colormaps/freeze/freeze.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/fusion/fusion.py b/cmasher/colormaps/fusion/fusion.py index e99f4840..474c0781 100644 --- a/cmasher/colormaps/fusion/fusion.py +++ b/cmasher/colormaps/fusion/fusion.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -537,5 +537,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/gem/gem.py b/cmasher/colormaps/gem/gem.py index 6adc0631..41bca5ae 100644 --- a/cmasher/colormaps/gem/gem.py +++ b/cmasher/colormaps/gem/gem.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/ghostlight/ghostlight.py b/cmasher/colormaps/ghostlight/ghostlight.py index 4fadb7fa..d737193c 100644 --- a/cmasher/colormaps/ghostlight/ghostlight.py +++ b/cmasher/colormaps/ghostlight/ghostlight.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/gothic/gothic.py b/cmasher/colormaps/gothic/gothic.py index a4b75b3b..0beeeae2 100644 --- a/cmasher/colormaps/gothic/gothic.py +++ b/cmasher/colormaps/gothic/gothic.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/guppy/guppy.py b/cmasher/colormaps/guppy/guppy.py index 0ca4e427..5b7fa1c0 100644 --- a/cmasher/colormaps/guppy/guppy.py +++ b/cmasher/colormaps/guppy/guppy.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -537,5 +537,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/holly/holly.py b/cmasher/colormaps/holly/holly.py index f905b3ae..49a88ad5 100644 --- a/cmasher/colormaps/holly/holly.py +++ b/cmasher/colormaps/holly/holly.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -537,5 +537,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/horizon/horizon.py b/cmasher/colormaps/horizon/horizon.py index 49c2612e..1cfb9018 100644 --- a/cmasher/colormaps/horizon/horizon.py +++ b/cmasher/colormaps/horizon/horizon.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/iceburn/iceburn.py b/cmasher/colormaps/iceburn/iceburn.py index 4b0ca919..36bc7603 100644 --- a/cmasher/colormaps/iceburn/iceburn.py +++ b/cmasher/colormaps/iceburn/iceburn.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -537,5 +537,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/infinity/infinity.py b/cmasher/colormaps/infinity/infinity.py index c9bd660a..56aef056 100644 --- a/cmasher/colormaps/infinity/infinity.py +++ b/cmasher/colormaps/infinity/infinity.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -536,8 +536,8 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) # Determine central value index of the colormap idx = len(cm_data) // 2 @@ -551,5 +551,5 @@ cmap_s_r = cmap_s.reversed() # Register shifted versions in MPL as well -register_cmap(cmap=cmap_s) -register_cmap(cmap=cmap_s_r) +mpl.colormaps.register(cmap=cmap_s) +mpl.colormaps.register(cmap=cmap_s_r) diff --git a/cmasher/colormaps/jungle/jungle.py b/cmasher/colormaps/jungle/jungle.py index 1b386ed5..a55d2965 100644 --- a/cmasher/colormaps/jungle/jungle.py +++ b/cmasher/colormaps/jungle/jungle.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/lavender/lavender.py b/cmasher/colormaps/lavender/lavender.py index 3d923fbf..d7dc9010 100644 --- a/cmasher/colormaps/lavender/lavender.py +++ b/cmasher/colormaps/lavender/lavender.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/lilac/lilac.py b/cmasher/colormaps/lilac/lilac.py index 1b62feb6..6aa27e1a 100644 --- a/cmasher/colormaps/lilac/lilac.py +++ b/cmasher/colormaps/lilac/lilac.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/neon/neon.py b/cmasher/colormaps/neon/neon.py index a42c8969..83b732e9 100644 --- a/cmasher/colormaps/neon/neon.py +++ b/cmasher/colormaps/neon/neon.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/neutral/neutral.py b/cmasher/colormaps/neutral/neutral.py index dd3424d6..49121fae 100644 --- a/cmasher/colormaps/neutral/neutral.py +++ b/cmasher/colormaps/neutral/neutral.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -2586,5 +2586,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/nuclear/nuclear.py b/cmasher/colormaps/nuclear/nuclear.py index 8513a28e..6fd7ee59 100644 --- a/cmasher/colormaps/nuclear/nuclear.py +++ b/cmasher/colormaps/nuclear/nuclear.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/ocean/ocean.py b/cmasher/colormaps/ocean/ocean.py index 960bd10c..1696fe6d 100644 --- a/cmasher/colormaps/ocean/ocean.py +++ b/cmasher/colormaps/ocean/ocean.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/pepper/pepper.py b/cmasher/colormaps/pepper/pepper.py index 09a541d3..58f7f591 100644 --- a/cmasher/colormaps/pepper/pepper.py +++ b/cmasher/colormaps/pepper/pepper.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/pride/pride.py b/cmasher/colormaps/pride/pride.py index 3be7d0b9..a16b4181 100644 --- a/cmasher/colormaps/pride/pride.py +++ b/cmasher/colormaps/pride/pride.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -537,5 +537,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/prinsenvlag/prinsenvlag.py b/cmasher/colormaps/prinsenvlag/prinsenvlag.py index d12bbb58..e9de085d 100644 --- a/cmasher/colormaps/prinsenvlag/prinsenvlag.py +++ b/cmasher/colormaps/prinsenvlag/prinsenvlag.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -537,5 +537,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/rainforest/rainforest.py b/cmasher/colormaps/rainforest/rainforest.py index 763581f4..6f1e25d7 100644 --- a/cmasher/colormaps/rainforest/rainforest.py +++ b/cmasher/colormaps/rainforest/rainforest.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/redshift/redshift.py b/cmasher/colormaps/redshift/redshift.py index 71462f83..b797c4f9 100644 --- a/cmasher/colormaps/redshift/redshift.py +++ b/cmasher/colormaps/redshift/redshift.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -537,5 +537,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/sapphire/sapphire.py b/cmasher/colormaps/sapphire/sapphire.py index b149dc64..8e784a0d 100644 --- a/cmasher/colormaps/sapphire/sapphire.py +++ b/cmasher/colormaps/sapphire/sapphire.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/savanna/savanna.py b/cmasher/colormaps/savanna/savanna.py index 4c16e4a5..15265d67 100644 --- a/cmasher/colormaps/savanna/savanna.py +++ b/cmasher/colormaps/savanna/savanna.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/seasons/seasons.py b/cmasher/colormaps/seasons/seasons.py index 668849c5..93f8df0b 100644 --- a/cmasher/colormaps/seasons/seasons.py +++ b/cmasher/colormaps/seasons/seasons.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -536,8 +536,8 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) # Determine central value index of the colormap idx = len(cm_data) // 2 @@ -551,5 +551,5 @@ cmap_s_r = cmap_s.reversed() # Register shifted versions in MPL as well -register_cmap(cmap=cmap_s) -register_cmap(cmap=cmap_s_r) +mpl.colormaps.register(cmap=cmap_s) +mpl.colormaps.register(cmap=cmap_s_r) diff --git a/cmasher/colormaps/seaweed/seaweed.py b/cmasher/colormaps/seaweed/seaweed.py index a460eb38..cda195e0 100644 --- a/cmasher/colormaps/seaweed/seaweed.py +++ b/cmasher/colormaps/seaweed/seaweed.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -537,5 +537,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/sepia/sepia.py b/cmasher/colormaps/sepia/sepia.py index e87d1ca5..24d8f1bf 100644 --- a/cmasher/colormaps/sepia/sepia.py +++ b/cmasher/colormaps/sepia/sepia.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/sunburst/sunburst.py b/cmasher/colormaps/sunburst/sunburst.py index f0d2f542..c79e6fcb 100644 --- a/cmasher/colormaps/sunburst/sunburst.py +++ b/cmasher/colormaps/sunburst/sunburst.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/swamp/swamp.py b/cmasher/colormaps/swamp/swamp.py index 9daab8ed..d0684e2f 100644 --- a/cmasher/colormaps/swamp/swamp.py +++ b/cmasher/colormaps/swamp/swamp.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/torch/torch.py b/cmasher/colormaps/torch/torch.py index 7b811b09..f4dc6d5a 100644 --- a/cmasher/colormaps/torch/torch.py +++ b/cmasher/colormaps/torch/torch.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/toxic/toxic.py b/cmasher/colormaps/toxic/toxic.py index 859cf557..7e05bbcd 100644 --- a/cmasher/colormaps/toxic/toxic.py +++ b/cmasher/colormaps/toxic/toxic.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/tree/tree.py b/cmasher/colormaps/tree/tree.py index 167edc9a..81676323 100644 --- a/cmasher/colormaps/tree/tree.py +++ b/cmasher/colormaps/tree/tree.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/tropical/tropical.py b/cmasher/colormaps/tropical/tropical.py index 92433c23..de4836e5 100644 --- a/cmasher/colormaps/tropical/tropical.py +++ b/cmasher/colormaps/tropical/tropical.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/viola/viola.py b/cmasher/colormaps/viola/viola.py index 5518be73..49227f79 100644 --- a/cmasher/colormaps/viola/viola.py +++ b/cmasher/colormaps/viola/viola.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -537,5 +537,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/voltage/voltage.py b/cmasher/colormaps/voltage/voltage.py index 3c61175a..82cb7547 100644 --- a/cmasher/colormaps/voltage/voltage.py +++ b/cmasher/colormaps/voltage/voltage.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -282,5 +282,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/waterlily/waterlily.py b/cmasher/colormaps/waterlily/waterlily.py index bcaf3fcc..3ee26989 100644 --- a/cmasher/colormaps/waterlily/waterlily.py +++ b/cmasher/colormaps/waterlily/waterlily.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -537,5 +537,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/watermelon/watermelon.py b/cmasher/colormaps/watermelon/watermelon.py index 32e757a7..913699c8 100644 --- a/cmasher/colormaps/watermelon/watermelon.py +++ b/cmasher/colormaps/watermelon/watermelon.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -537,5 +537,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/colormaps/wildfire/wildfire.py b/cmasher/colormaps/wildfire/wildfire.py index 66e7ef30..ac594c8f 100644 --- a/cmasher/colormaps/wildfire/wildfire.py +++ b/cmasher/colormaps/wildfire/wildfire.py @@ -1,6 +1,6 @@ # %% IMPORTS # Package imports -from matplotlib.cm import register_cmap +import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -537,5 +537,5 @@ cmap_r = cmap.reversed() # Register (reversed) cmap in MPL -register_cmap(cmap=cmap) -register_cmap(cmap=cmap_r) +mpl.colormaps.register(cmap=cmap) +mpl.colormaps.register(cmap=cmap_r) diff --git a/cmasher/tests/test_utils.py b/cmasher/tests/test_utils.py index 63915fd5..38d15320 100644 --- a/cmasher/tests/test_utils.py +++ b/cmasher/tests/test_utils.py @@ -6,10 +6,10 @@ # Package imports import cmocean as cmo +import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np import pytest -from matplotlib import cm as mplcm from matplotlib.colors import ListedColormap as LC from matplotlib.legend import Legend @@ -54,7 +54,7 @@ class Test_create_cmap_mod: # Test if a standalone module of rainforest can be created def test_standalone_rainforest(self): # Obtain the currently registered version of rainforest - cmap_old = mplcm.get_cmap("cmr.rainforest") + cmap_old = mpl.colormaps["cmr.rainforest"] # Create standalone module for rainforest cmap_path = create_cmap_mod("rainforest", _copy_name="rainforest_copy") @@ -65,9 +65,9 @@ def test_standalone_rainforest(self): spec.loader.exec_module(mod) # Check if the colormap in MPL has been updated - cmap_new = mplcm.get_cmap("cmr.rainforest_copy") + cmap_new = mpl.colormaps["cmr.rainforest_copy"] - # identity equality isn't achievable since mplcm.get_cmap may return a copy + # identity equality isn't achievable since mpl.colormaps.get_cmap may return a copy assert cmap_new == mod.cmap assert cmap_old == cmap_new @@ -77,7 +77,7 @@ def test_standalone_rainforest(self): # Test if a standalone module of infinity can be created def test_standalone_infinity(self): # Obtain the currently registered version of infinity - cmap_old = mplcm.get_cmap("cmr.infinity") + cmap_old = mpl.colormaps["cmr.infinity"] # Create standalone module for infinity cmap_path = create_cmap_mod("infinity", _copy_name="inifinity_copy") @@ -88,7 +88,7 @@ def test_standalone_infinity(self): spec.loader.exec_module(mod) # Check if the colormap in MPL has been updated - cmap_new = mplcm.get_cmap("cmr.infinity") + cmap_new = mpl.colormaps["cmr.infinity"] assert cmap_new == mod.cmap assert cmap_old == cmap_new @@ -124,7 +124,7 @@ def test_list_cat(self): # Test if providing all MPL colormap objects works def test_mpl_cmaps_objs(self): - cmaps = map(mplcm.get_cmap, mpl_cmaps) + cmaps = map(mpl.colormaps.get_cmap, mpl_cmaps) create_cmap_overview(cmaps, sort="perceptual") # Test if providing all MPL colormap names works @@ -223,7 +223,7 @@ def test_CMasher_cmaps(self, cm_name): # Check if provided cm_name is registered in CMasher and MPL for name in (cm_name, cm_name + "_r"): cmr_cmap = getattr(cmr, name) - mpl_cmap = mplcm.get_cmap("cmr." + name) + mpl_cmap = mpl.colormaps["cmr." + name] assert isinstance(cmr_cmap, LC) assert isinstance(mpl_cmap, LC) assert getattr(cmrcm, name) is cmr_cmap diff --git a/cmasher/utils.py b/cmasher/utils.py index d8e780dc..9fa8fe01 100644 --- a/cmasher/utils.py +++ b/cmasher/utils.py @@ -15,6 +15,7 @@ from textwrap import dedent from typing import Callable, Iterable, List, Optional, Tuple, Union +import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np @@ -116,7 +117,7 @@ def _get_cmap_lightness_rank(cmap: CMAP) -> Tuple[int, int, float, float, float, """ # Obtain the colormap - cmap = mplcm.get_cmap(cmap) + cmap = mpl.colormaps.get_cmap(cmap) cm_type = get_cmap_type(cmap) # Determine lightness profile stats for sequential/diverging/cyclic @@ -214,7 +215,7 @@ def _get_cmap_perceptual_rank( """ # Obtain the colormap - cmap = mplcm.get_cmap(cmap) + cmap = mpl.colormaps.get_cmap(cmap) cm_type = get_cmap_type(cmap) # Determine perceptual range for sequential/diverging/cyclic @@ -324,7 +325,7 @@ def create_cmap_mod( """ # %% IMPORTS # Package imports - from matplotlib.cm import register_cmap + import matplotlib as mpl from matplotlib.colors import ListedColormap # All declaration @@ -349,8 +350,8 @@ def create_cmap_mod( cmap_r = cmap.reversed() # Register (reversed) cmap in MPL - register_cmap(cmap=cmap) - register_cmap(cmap=cmap_r) + mpl.colormaps.register(cmap=cmap) + mpl.colormaps.register(cmap=cmap_r) """ ) @@ -367,8 +368,8 @@ def create_cmap_mod( cmap_s_r = cmap_s.reversed() # Register shifted versions in MPL as well - register_cmap(cmap=cmap_s) - register_cmap(cmap=cmap_s_r) + mpl.colormaps.register(cmap=cmap_s) + mpl.colormaps.register(cmap=cmap_s_r) """ ) @@ -528,7 +529,7 @@ def sort(x): # Loop over all cmaps and add their Colormap objects for cmap in cmaps: if isinstance(cmap, str): - cmaps_dict[cm_type].append(mplcm.get_cmap(cmap)) + cmaps_dict[cm_type].append(mpl.colormaps.get_cmap(cmap)) else: cmaps_dict[cm_type].append(cmap) @@ -544,14 +545,14 @@ def sort(x): for cmap in cmaps: cm_type = get_cmap_type(cmap) if isinstance(cmap, str): - cmaps_dict[cm_type].append(mplcm.get_cmap(cmap)) + cmaps_dict[cm_type].append(mpl.colormaps.get_cmap(cmap)) else: cmaps_dict[cm_type].append(cmap) else: # Loop over all cmaps and add their Colormap objects for cmap in cmaps: if isinstance(cmap, str): - cmaps_list.append(mplcm.get_cmap(cmap)) + cmaps_list.append(mpl.colormaps.get_cmap(cmap)) else: cmaps_list.append(cmap) @@ -920,7 +921,7 @@ def get_cmap_type(cmap: CMAP) -> str: """ # Obtain the colormap - cmap = mplcm.get_cmap(cmap) + cmap = mpl.colormaps.get_cmap(cmap) # Get RGB values for colormap rgb = cmap(np.arange(cmap.N))[:, :3] @@ -1040,7 +1041,7 @@ def get_sub_cmap( """ # Obtain the colormap - cmap = mplcm.get_cmap(cmap) + cmap = mpl.colormaps.get_cmap(cmap) # Check value of N to determine suffix for the name suffix = "_sub" if N is None else "_qual" @@ -1259,14 +1260,14 @@ def register_cmap(name: str, data: RGB) -> None: cm_type = get_cmap_type(cmap_mpl) # Add cmap to matplotlib's cmap list - mplcm.register_cmap(cmap=cmap_mpl) + mpl.colormaps.register(cmap=cmap_mpl) setattr(cmrcm, cmap_cmr.name, cmap_cmr) cmrcm.__all__.append(cmap_cmr.name) cmrcm.cmap_d[cmap_cmr.name] = cmap_cmr cmrcm.cmap_cd[cm_type][cmap_cmr.name] = cmap_cmr # Add reversed cmap to matplotlib's cmap list - mplcm.register_cmap(cmap=cmap_mpl_r) + mpl.colormaps.register(cmap=cmap_mpl_r) setattr(cmrcm, cmap_cmr_r.name, cmap_cmr_r) cmrcm.__all__.append(cmap_cmr_r.name) cmrcm.cmap_d[cmap_cmr_r.name] = cmap_cmr_r @@ -1394,7 +1395,7 @@ def take_cmap_colors( return_fmt = return_fmt.lower() # Obtain the colormap - cmap = mplcm.get_cmap(cmap) + cmap = mpl.colormaps.get_cmap(cmap) # Check if provided cmap_range is valid if not ((0 <= cmap_range[0] <= 1) and (0 <= cmap_range[1] <= 1)): @@ -1455,7 +1456,7 @@ def view_cmap( """ # Obtain cmap - cmap = mplcm.get_cmap(cmap) + cmap = mpl.colormaps.get_cmap(cmap) # Check if show_grayscale is True if show_grayscale: