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):
272272 1) a letter from the set 'rgbcmykw'
273273 2) a hex color string, like '#00FFFF'
274274 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
276277
277278 if *arg* is *RGBA*, the *A* will simply be discarded.
278279 """
280+ # Gray must be a string to distinguish 3-4 grays from RGB or RGBA.
281+
279282 try :
280283 return self .cache [arg ]
281284 except KeyError :
@@ -304,7 +307,7 @@ def to_rgb(self, arg):
304307 if fl < 0 or fl > 1 :
305308 raise ValueError (
306309 'gray (string) must be in range 0-1' )
307- color = tuple ([ fl ] * 3 )
310+ color = ( fl ,) * 3
308311 elif cbook .iterable (arg ):
309312 if len (arg ) > 4 or len (arg ) < 3 :
310313 raise ValueError (
Original file line number Diff line number Diff line change @@ -192,6 +192,19 @@ def test_autoscale_masked():
192192 plt .draw ()
193193
194194
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+
195208if __name__ == '__main__' :
196209 import nose
197210 nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
You can’t perform that action at this time.
0 commit comments