Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bb2de5e

Browse filesBrowse files
committed
Support setting rcParams["image.cmap"] to Colormap instances.
This makes it possible to set the rcParam to a non-registered colormap (which cannot be referred to by name). A use-case is to set it to e.g. `viridis.with_extremes(bad="k")`.
1 parent 7a5458b commit bb2de5e
Copy full SHA for bb2de5e

File tree

Expand file treeCollapse file tree

2 files changed

+13
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-2
lines changed

‎doc/users/next_whats_new/2019-06-28-AL.rst

Copy file name to clipboardExpand all lines: doc/users/next_whats_new/2019-06-28-AL.rst
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ first copy the colormap and set the extreme colors on that copy.
1111
The new `.Colormap.set_extremes` method is provided for API symmetry with
1212
`.Colormap.with_extremes`, but note that it suffers from the same issue as the
1313
earlier individual setters.
14+
15+
Additionally, it is now possible to set :rc:`image.cmap` to a `.Colormap`
16+
instance, such as a new colormap created with `~.Colormap.set_extremes`. (This
17+
can only be done from Python code, not from the :file:`matplotlibrc` file.)

‎lib/matplotlib/rcsetup.py

Copy file name to clipboardExpand all lines: lib/matplotlib/rcsetup.py
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from matplotlib import _api, animation, cbook
2626
from matplotlib.cbook import ls_mapper
2727
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
28-
from matplotlib.colors import is_color_like
28+
from matplotlib.colors import Colormap, is_color_like
2929

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

394394
validate_colorlist = _listify_validator(
395395
validate_color, allow_stringlist=True, doc='return a list of colorspecs')
396+
397+
398+
def _validate_cmap(s):
399+
cbook._check_isinstance((str, Colormap), cmap=s)
400+
return s
401+
402+
396403
validate_orientation = ValidateInStrings(
397404
'orientation', ['landscape', 'portrait'], _deprecated_since="3.3")
398405

@@ -1141,7 +1148,7 @@ def _convert_validator_spec(key, conv):
11411148

11421149
"image.aspect": validate_aspect, # equal, auto, a number
11431150
"image.interpolation": validate_string,
1144-
"image.cmap": validate_string, # gray, jet, etc.
1151+
"image.cmap": _validate_cmap, # gray, jet, etc.
11451152
"image.lut": validate_int, # lookup table
11461153
"image.origin": ["upper", "lower"],
11471154
"image.resample": validate_bool,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.