8000 Support setting rcParams["image.cmap"] to Colormap instances. by anntzer · Pull Request #19106 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Support setting rcParams["image.cmap"] to Colormap instances. #19106

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
Dec 15, 2020
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/users/next_whats_new/2019-06-28-AL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ first copy the colormap and set the extreme colors on that copy.
The new `.Colormap.set_extremes` method is provided for API symmetry with
`.Colormap.with_extremes`, but note that it suffers from the same issue as the
earlier individual setters.

Additionally, it is now possible to set :rc:`image.cmap` to a `.Colormap`
instance, such as a new colormap created with `~.Colormap.set_extremes`. (This
can only be done from Python code, not from the :file:`matplotlibrc` file.)
11 changes: 9 additions & 2 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from matplotlib import _api, animation, cbook
from matplotlib.cbook import ls_mapper
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
from matplotlib.colors import is_color_like
from matplotlib.colors import Colormap, is_color_like

# Don't let the original cycler collide with our validating cycler
from cycler import Cycler, cycler as ccycler
Expand Down Expand Up @@ -393,6 +393,13 @@ def validate_color(s):

validate_colorlist = _listify_validator(
validate_color, allow_stringlist=True, doc='return a list of colorspecs')


def _validate_cmap(s):
cbook._check_isinstance((str, Colormap), cmap=s)
return s


validate_orientation = ValidateInStrings(
'orientation', ['landscape', 'portrait'], _deprecated_since="3.3")

Expand Down Expand Up @@ -1141,7 +1148,7 @@ def _convert_validator_spec(key, conv):

"image.aspect": validate_aspect, # equal, auto, a number
"image.interpolation": validate_string,
"image.cmap": validate_string, # gray, jet, etc.
"image.cmap": _validate_cmap, # gray, jet, etc.
"image.lut": validate_int, # lookup table
"image.origin": ["upper", "lower"],
"image.resample": validate_bool,
Expand Down
0