File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -272,10 +272,13 @@ def to_rgb(self, arg):
272
272
1) a letter from the set 'rgbcmykw'
273
273
2) a hex color string, like '#00FFFF'
274
274
3) a standard name, like 'aqua'
275
- 4) a float, like '0.4', indicating gray on a 0-1 scale
275
+ 4) a string representation of a float, like '0.4',
276
+ indicating gray on a 0-1 scale
276
277
277
278
if *arg* is *RGBA*, the *A* will simply be discarded.
278
279
"""
280
+ # Gray must be a string to distinguish 3-4 grays from RGB or RGBA.
281
+
279
282
try :
280
283
return self .cache [arg ]
281
284
except KeyError :
@@ -304,7 +307,7 @@ def to_rgb(self, arg):
304
307
if fl < 0 or fl > 1 :
305
308
raise ValueError (
306
309
'gray (string) must be in range 0-1' )
307
- color = tuple ([ fl ] * 3 )
310
+ color = ( fl ,) * 3
308
311
elif cbook .iterable (arg ):
309
312
if len (arg ) > 4 or len (arg ) < 3 :
310
313
raise ValueError (
Original file line number Diff line number Diff line change @@ -192,6 +192,19 @@ def test_autoscale_masked():
192
192
plt .draw ()
193
193
194
194
195
+ def test_colors_no_float ():
196
+ # Gray must be a string to distinguish 3-4 grays from RGB or RGBA.
197
+
198
+ def gray_from_float_rgb ():
199
+ return mcolors .colorConverter .to_rgb (0.4 )
200
+
201
+ def gray_from_float_rgba ():
202
+ return mcolors .colorConverter .to_rgba (0.4 )
203
+
204
+ assert_raises (ValueError , gray_from_float_rgb )
205
+ assert_raises (ValueError , gray_from_float_rgba )
206
+
207
+
195
208
if __name__ == '__main__' :
196
209
import nose
197
210
nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
You can’t perform that action at this time.
0 commit comments