2828import numpy as np
2929import numpy .ma as ma
3030
31+ from matplotlib import colormaps as mcolormaps
3132from .config import rc
3233from .internals import ic # noqa: F401
3334from .internals import (
@@ -2861,8 +2862,11 @@ def _init_cmap_database():
28612862 database = getattr (mcm , attr )
28622863 if mcm .get_cmap is not _get_cmap :
28632864 mcm .get_cmap = _get_cmap
2864- if mcm .register_cmap is not _register_cmap :
2865- mcm .register_cmap = _register_cmap
2865+ # enable backward compatibility
2866+ if hasattr (mcm , "register_cmap" ):
2867+ if mcm .register_cmap is not wrap_register_cmap :
2868+ mcm .register_cmap = wrap_register_cmap
2869+
28662870 if not isinstance (database , ColormapDatabase ):
28672871 database = {
28682872 key : value
@@ -2874,19 +2878,23 @@ def _init_cmap_database():
28742878 return database
28752879
28762880
2877- _mpl_register_cmap = mcm .register_cmap
2881+ def wrap_register_cmap (* args , ** kwargs ):
2882+ # This function is merely to wrap register cmap
2883+ # to prevent adding unnecessary trigger warnings
2884+ original_register_cmap = mcm .register_cmap
28782885
2886+ @functools .wraps (original_register_cmap ) # noqa: E302
2887+ def _register_cmap (* args , ** kwargs ):
2888+ """
2889+ Monkey patch for `~matplotlib.cm.register_cmap`. Ignores warning
2890+ message when re-registering existing colormaps. This is unnecessary
2891+ and triggers 100 warnings when importing seaborn.
2892+ """
2893+ with warnings .catch_warnings ():
2894+ warnings .simplefilter ("ignore" , UserWarning )
2895+ return mcm .register_cmap (* args , ** kwargs )
28792896
2880- @functools .wraps (_mpl_register_cmap ) # noqa: E302
2881- def _register_cmap (* args , ** kwargs ):
2882- """
2883- Monkey patch for `~matplotlib.cm.register_cmap`. Ignores warning
2884- message when re-registering existing colormaps. This is unnecessary
2885- and triggers 100 warnings when importing seaborn.
2886- """
2887- with warnings .catch_warnings ():
2888- warnings .simplefilter ("ignore" , UserWarning )
2889- return _mpl_register_cmap (* args , ** kwargs )
2897+ return wrapped_register_cmap
28902898
28912899
28922900@functools .wraps (mcm .get_cmap )
0 commit comments