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

Skip to content

Commit cb25841

Browse files
committed
Add earlier color validation
1 parent ec0132f commit cb25841

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

lib/matplotlib/cbook/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,7 +2242,7 @@ def type_name(tp):
22422242
type_name(type(v))))
22432243

22442244

2245-
def _check_in_list(_values, **kwargs):
2245+
def _check_in_list(_values, _print_supported_values=True, **kwargs):
22462246
"""
22472247
For each *key, value* pair in *kwargs*, check that *value* is in *_values*;
22482248
if not, raise an appropriate ValueError.
@@ -2254,9 +2254,13 @@ def _check_in_list(_values, **kwargs):
22542254
values = _values
22552255
for k, v in kwargs.items():
22562256
if v not in values:
2257-
raise ValueError(
2258-
"{!r} is not a valid value for {}; supported values are {}"
2259-
.format(v, k, ', '.join(map(repr, values))))
2257+
if _print_supported_values:
2258+
raise ValueError(
2259+
"{!r} is not a valid value for {}; supported values are {}"
2260+
.format(v, k, ', '.join(map(repr, values))))
2261+
else:
2262+
raise ValueError(
2263+
"{!r} is not a valid value for {}".format(v, k))
22602264

22612265

22622266
def _check_shape(_shape, **kwargs):

lib/matplotlib/lines.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .artist import Artist, allow_rasterization
1515
from .cbook import (
1616
_to_unmasked_float_array, ls_mapper, ls_mapper_r, STEP_LOOKUP_MAP)
17+
from .colors import is_color_like, get_named_colors_mapping
1718
from .markers import MarkerStyle
1819
from .path import Path
1920
from .transforms import (
@@ -1039,6 +1040,9 @@ def set_color(self, color):
10391040
----------
10401041
color : color
10411042
"""
1043+
if not is_color_like(color):
1044+
cbook._check_in_list(get_named_colors_mapping(),
1045+
_print_supported_values=False, color=color)
10421046
self._color = color
10431047
self.stale = True
10441048

0 commit comments

Comments
 (0)