Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Deprecate matplotlib.cm.LUTSIZE #20806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/api/next_api_changes/deprecations/20806-TH.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``matplotlib.cm.LUTSIZE``
~~~~~~~~~~~~~~~~~~~~~~~~~
is deprecated. Use :rc:`image.lut` instead. This value only affects colormap
quantization levels for default colormaps generated at module import time.
16 changes: 13 additions & 3 deletions lib/matplotlib/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

from collections.abc import Mapping, MutableMapping
import functools

import numpy as np
from numpy import ma
Expand All @@ -26,7 +27,16 @@
from matplotlib._cm_listed import cmaps as cmaps_listed


LUTSIZE = mpl.rcParams['image.lut']
# module-level deprecations.
@functools.lru_cache(None)
def __getattr__(name):
if name == "LUTSIZE":
_api.warn_deprecated("3.5", name=name,
alternative="rcParams['image.lut']")
return _LUTSIZE


_LUTSIZE = mpl.rcParams['image.lut']


def _gen_cmap_registry():
Expand All @@ -37,11 +47,11 @@ def _gen_cmap_registry():
cmap_d = {**cmaps_listed}
for name, spec in datad.items():
cmap_d[name] = ( # Precache the cmaps at a fixed lutsize..
colors.LinearSegmentedColormap(name, spec, LUTSIZE)
colors.LinearSegmentedColormap(name, spec, _LUTSIZE)
if 'red' in spec else
colors.ListedColormap(spec['listed'], name)
if 'listed' in spec else
colors.LinearSegmentedColormap.from_list(name, spec, LUTSIZE))
colors.LinearSegmentedColormap.from_list(name, spec, _LUTSIZE))
# Generate reversed cmaps.
for cmap in list(cmap_d.values()):
rmap = cmap.reversed()
Expand Down