Backport PR #10721 on branch v2.2.x by lumberbot-app[bot] · Pull Request #10730 · matplotlib/matplotlib · GitHub
Skip to content
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: 2 additions & 2 deletions lib/matplotlib/cm.py
14 changes: 12 additions & 2 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ def get_named_colors_mapping():
return _colors_full_map


def _sanitize_extrema(ex):
if ex is None:
return ex
try:
ret = np.asscalar(ex)
except AttributeError:
ret = float(ex)
return ret


def _is_nth_color(c):
"""Return whether *c* can be interpreted as an item in the color cycle."""
return isinstance(c, six.string_types) and re.match(r"\AC[0-9]\Z", c)
Expand Down Expand Up @@ -878,8 +888,8 @@ def __init__(self, vmin=None, vmax=None, clip=False):
likely to lead to surprises; therefore the default is
*clip* = *False*.
"""
self.vmin = vmin
self.vmax = vmax
self.vmin = _sanitize_extrema(vmin)
self.vmax = _sanitize_extrema(vmax)
self.clip = clip

@staticmethod
Expand Down
9 changes: 8 additions & 1 deletion lib/matplotlib/tests/test_colors.py