File tree Expand file tree Collapse file tree 4 files changed +20
-4
lines changed
Filter options
Expand file tree Collapse file tree 4 files changed +20
-4
lines changed
Original file line number Diff line number Diff line change @@ -147,6 +147,15 @@ def is_color_like(c):
147
147
return True
148
148
149
149
150
+ def _check_color_like (** kwargs ):
151
+ """
152
+ For each *key, value* pair in *kwargs*, check that *value* is color-like.
153
+ """
154
+ for k , v in kwargs .items ():
155
+ if not is_color_like (v ):
156
+ raise ValueError (f"{ v !r} is not a valid value for { k } " )
157
+
158
+
150
159
def same_color (c1 , c2 ):
151
160
"""
152
161
Return whether the colors *c1* and *c2* are the same.
Original file line number Diff line number Diff line change 13
13
from .artist import Artist , allow_rasterization
14
14
from .cbook import (
15
15
_to_unmasked_float_array , ls_mapper , ls_mapper_r , STEP_LOOKUP_MAP )
16
- from .colors import is_color_like , get_named_colors_mapping
17
16
from .markers import MarkerStyle
18
17
from .path import Path
19
18
from .transforms import Bbox , BboxTransformTo , TransformedPath
@@ -1050,9 +1049,8 @@ def set_color(self, color):
1050
1049
----------
1051
1050
color : color
1052
1051
"""
1053
- if not is_color_like (color ) and color != 'auto' :
1054
- _api .check_in_list (get_named_colors_mapping (),
1055
- _print_supported_values = False , color = color )
1052
+ if not cbook ._str_equal (color , 'auto' ):
1053
+ mcolors ._check_color_like (color = color )
1056
1054
self ._color = color
1057
1055
self .stale = True
1058
1056
Original file line number Diff line number Diff line change @@ -709,3 +709,8 @@ def test_update_mutate_input():
709
709
t .update (inp )
710
710
assert inp ['fontproperties' ] == cache ['fontproperties' ]
711
711
assert inp ['bbox' ] == cache ['bbox' ]
712
+
713
+
714
+ def test_invalid_color ():
715
+ with pytest .raises (ValueError ):
716
+ plt .figtext (.5 , .5 , "foo" , c = "foobar" )
Original file line number Diff line number Diff line change @@ -934,6 +934,10 @@ def set_color(self, color):
934
934
----------
935
935
color : color
936
936
"""
937
+ # "auto" is only supported by axisartist, but we can just let it error
938
+ # out at draw time for simplicity.
939
+ if not cbook ._str_equal (color , "auto" ):
940
+ mpl .colors ._check_color_like (color = color )
937
941
# Make sure it is hashable, or get_prop_tup will fail.
938
942
try :
939
943
hash (color )
You can’t perform that action at this time.
0 commit comments