1515# transitions because specifying N greater than len(colors) will cyclically loop around
1616# the colors or truncate colors. Therefore we always encode smooth color transitions
1717# with LinearSegmentedColormap and translate cmaps accordingly (rc['cmap.listedthesh'])
18+ import functools
1819import json
1920import os
2021import re
@@ -2717,6 +2718,8 @@ def _init_cmap_database():
27172718 database = getattr (mcm , attr )
27182719 if mcm .get_cmap is not _get_cmap :
27192720 mcm .get_cmap = _get_cmap
2721+ if mcm .register_cmap is not _register_cmap :
2722+ mcm .register_cmap = _register_cmap
27202723 if not isinstance (database , ColormapDatabase ):
27212724 database = {
27222725 key : value for key , value in database .items ()
@@ -2727,23 +2730,26 @@ def _init_cmap_database():
27272730 return database
27282731
27292732
2730- def _get_cmap (name = None , lut = None ):
2733+ _mpl_register_cmap = mcm .register_cmap
2734+ @functools .wraps (_mpl_register_cmap ) # noqa: E302
2735+ def _register_cmap (* args , ** kwargs ):
2736+ """
2737+ Monkey patch for `~matplotlib.cm.register_cmap`. Ignores warning
2738+ message when re-registering existing colormaps. This is unnecessary
2739+ and triggers 100 warnings when importing seaborn.
27312740 """
2732- Return the registered colormap instance.
2741+ with warnings .catch_warnings ():
2742+ warnings .simplefilter ('ignore' , UserWarning )
2743+ return _mpl_register_cmap (* args , ** kwargs )
27332744
2734- Parameters
2735- ----------
2736- name : `matplotlib.colors.Colormap` or str or None, optional
2737- If a `~matplotlib.colors.Colormap` instance, it will be returned. Otherwise,
2738- the name of the registered colormap will be looked up and resampled by `lut`.
2739- If ``None``, the default colormap :rc:`image.cmap` is returned.
2740- lut : int or None, optional
2741- If `name` is not already a `~matplotlib.colors.Colormap` instance
2742- and `lut` is not None, the colormap will be resampled to have `lut`
2743- entries in the lookup table.
2745+
2746+ @functools .wraps (mcm .get_cmap ) # noqa: E302
2747+ def _get_cmap (name = None , lut = None ):
2748+ """
2749+ Monkey patch for `~matplotlib.cm.get_cmap`. Permits case-insensitive
2750+ search of monkey-patched colormap database. This was broken in v3.2.0
2751+ because matplotlib now uses _check_in_list with cmap dictionary keys.
27442752 """
2745- # Monkey patch for matplotlib `~matplotlib.get_cmap`. Permits case-insensitive
2746- # search of monkey-patched colormap database (which was broken in v3.2.0).
27472753 if name is None :
27482754 name = rc ['image.cmap' ]
27492755 if isinstance (name , mcolors .Colormap ):
0 commit comments