7171class _ColorMapping (dict ):
7272 def __init__ (self , mapping ):
7373 super (_ColorMapping , self ).__init__ (mapping )
74- self ._cache = {}
74+ self .cache = {}
7575
7676 def __setitem__ (self , key , value ):
7777 super (_ColorMapping , self ).__setitem__ (key , value )
78- self ._cache .clear ()
78+ self .cache .clear ()
7979
8080 def __delitem__ (self , key , value ):
8181 super (_ColorMapping , self ).__delitem__ (key , value )
82- self ._cache .clear ()
82+ self .cache .clear ()
8383
8484
8585_colors_full_map = {}
@@ -130,14 +130,14 @@ def to_rgba(c, alpha=None):
130130 if prop_cycler is None and 'axes.color_cycle' in rcParams :
131131 clist = rcParams ['axes.color_cycle' ]
132132 prop_cycler = cycler ('color' , clist )
133- colors = prop_cycler ._transpose ()[ 'color' ]
133+ colors = prop_cycler ._transpose (). get ( 'color' , 'k' )
134134 c = colors [int (c [1 ]) % len (colors )]
135135 try :
136- rgba = _colors_full_map ._cache [c , alpha ]
136+ rgba = _colors_full_map .cache [c , alpha ]
137137 except (KeyError , TypeError ): # Not in cache, or unhashable.
138138 rgba = _to_rgba_no_colorcycle (c , alpha )
139139 try :
140- _colors_full_map ._cache [c , alpha ] = rgba
140+ _colors_full_map .cache [c , alpha ] = rgba
141141 except TypeError :
142142 pass
143143 return rgba
@@ -233,6 +233,12 @@ def to_rgba_array(c, alpha=None):
233233 return result
234234
235235
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+
236242def to_hex (c , alpha = None ):
237243 """Convert `c` to a hex color.
238244
@@ -274,7 +280,7 @@ class ColorConverter(object):
274280 """
275281
276282 colors = _colors_full_map
277- cache = _colors_full_map ._cache
283+ cache = _colors_full_map .cache
278284
279285 @staticmethod
280286 def to_rgb (arg ):
@@ -292,7 +298,7 @@ def to_rgb(arg):
292298
293299 if *arg* is *RGBA*, the *A* will simply be discarded.
294300 """
295- return to_rgba (arg )[: 3 ]
301+ return to_rgb (arg )
296302
297303 @staticmethod
298304 def to_rgba (arg , alpha = None ):
0 commit comments