71
71
class _ColorMapping (dict ):
72
72
def __init__ (self , mapping ):
73
73
super (_ColorMapping , self ).__init__ (mapping )
74
- self ._cache = {}
74
+ self .cache = {}
75
75
76
76
def __setitem__ (self , key , value ):
77
77
super (_ColorMapping , self ).__setitem__ (key , value )
78
- self ._cache .clear ()
78
+ self .cache .clear ()
79
79
80
80
def __delitem__ (self , key , value ):
81
81
super (_ColorMapping , self ).__delitem__ (key , value )
82
- self ._cache .clear ()
82
+ self .cache .clear ()
83
83
84
84
85
85
_colors_full_map = {}
@@ -130,14 +130,14 @@ def to_rgba(c, alpha=None):
130
130
if prop_cycler is None and 'axes.color_cycle' in rcParams :
131
131
clist = rcParams ['axes.color_cycle' ]
132
132
prop_cycler = cycler ('color' , clist )
133
- colors = prop_cycler ._transpose ()[ 'color' ]
133
+ colors = prop_cycler ._transpose (). get ( 'color' , 'k' )
134
134
c = colors [int (c [1 ]) % len (colors )]
135
135
try :
136
- rgba = _colors_full_map ._cache [c , alpha ]
136
+ rgba = _colors_full_map .cache [c , alpha ]
137
137
except (KeyError , TypeError ): # Not in cache, or unhashable.
138
138
rgba = _to_rgba_no_colorcycle (c , alpha )
139
139
try :
140
- _colors_full_map ._cache [c , alpha ] = rgba
140
+ _colors_full_map .cache [c , alpha ] = rgba
141
141
except TypeError :
142
142
pass
143
143
return rgba
@@ -233,6 +233,12 @@ def to_rgba_array(c, alpha=None):
233
233
return result
234
234
235
235
236
+ def to_rgb (c ):
237
+ """Convert `c` to an RGB color, silently dropping the alpha channel.
238
+ """
239
+ return to_rgba (c )[:3 ]
240
+
241
+
236
242
def to_hex (c , alpha = None ):
237
243
"""Convert `c` to a hex color.
238
244
@@ -274,7 +280,7 @@ class ColorConverter(object):
274
280
"""
275
281
276
282
colors = _colors_full_map
277
- cache = _colors_full_map ._cache
283
+ cache = _colors_full_map .cache
278
284
279
285
@staticmethod
280
286
def to_rgb (arg ):
@@ -292,7 +298,7 @@ def to_rgb(arg):
292
298
293
299
if *arg* is *RGBA*, the *A* will simply be discarded.
294
300
"""
295
- return to_rgba (arg )[: 3 ]
301
+ return to_rgb (arg )
296
302
297
303
@staticmethod
298
304
def to_rgba (arg , alpha = None ):
0 commit comments