Skip to content

Commit

Permalink
BUG: fix an upcoming incompatibility with matplotlib 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed May 6, 2022
1 parent 63dc1aa commit 1accd5a
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions yt/visualization/color_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from packaging.version import Version

from yt.funcs import get_brewer_cmap
from yt.utilities.logger import ytLogger as mylog

from . import _colormap_data as _cm
from ._commons import MPL_VERSION
Expand Down Expand Up @@ -76,8 +77,6 @@ def register_yt_colormaps_from_cmyt():
"""
from matplotlib.pyplot import get_cmap

from yt.utilities.logger import ytLogger as mylog

for hist_name, alias in _HISTORICAL_ALIASES.items():
if MPL_VERSION >= Version("3.4.0"):
cmap = get_cmap(alias).copy()
Expand All @@ -91,25 +90,25 @@ def register_yt_colormaps_from_cmyt():
# Matplotlib 3.4.0 hard-forbids name collisions, but more recent versions
# will emit a warning instead, so we emulate this behaviour regardless.
mylog.warning("cannot register colormap '%s' (naming collision)", hist_name)
continue


register_yt_colormaps_from_cmyt()

# Add colormaps in _colormap_data.py that weren't defined here
_vs = np.linspace(0, 1, 256)
for k, v in list(_cm.color_map_luts.items()):
if k in yt_colormaps:
continue
cdict = {
"red": np.transpose([_vs, v[0], v[0]]),
"green": np.transpose([_vs, v[1], v[1]]),
"blue": np.transpose([_vs, v[2], v[2]]),
}
try:
colormaps = mcm._cmap_registry
except AttributeError: # mpl < 3.3.0
colormaps = mcm.cmap_d
if k not in yt_colormaps and k not in colormaps:
cdict = {
"red": np.transpose([_vs, v[0], v[0]]),
"green": np.transpose([_vs, v[1], v[1]]),
"blue": np.transpose([_vs, v[2], v[2]]),
}
add_colormap(k, cdict)
except ValueError:
# expected if another map with identical name was already registered
mylog.warning("cannot register colormap '%s' (naming collision)", k)


def get_colormap_lut(cmap_id: Union[Tuple[str, str], str]):
Expand Down

0 comments on commit 1accd5a

Please sign in to comment.