@@ -118,15 +118,16 @@ def is_color_like(c):
118
118
return True
119
119
120
120
121
- def to_rgba (c , alpha = None ):
121
+ def to_rgba (c , alpha = None , prop_cycler = None ):
122
122
"""Convert `c` to an RGBA color.
123
123
124
124
If `alpha` is not `None`, it forces the alpha value.
125
125
"""
126
126
# Special-case nth color syntax because it should not be cached.
127
127
if _is_nth_color (c ):
128
- from matplotlib import rcParams
129
- prop_cycler = rcParams ['axes.prop_cycle' ]
128
+ if prop_cycler is None :
129
+ from matplotlib import rcParams
130
+ prop_cycler = rcParams ['axes.prop_cycle' ]
130
131
colors = prop_cycler .by_key ().get ('color' , ['k' ])
131
132
c = colors [int (c [1 ]) % len (colors )]
132
133
try :
@@ -211,8 +212,8 @@ def to_rgba_array(c, alpha=None):
211
212
# Special-case inputs that are already arrays, for performance. (If the
212
213
# array has the wrong kind or shape, raise the error during one-at-a-time
213
214
# conversion.)
214
- if (isinstance (c , np .ndarray ) and c .dtype .kind in "if"
215
- and c .ndim == 2 and c .shape [1 ] in [3 , 4 ]):
215
+ if (isinstance (c , np .ndarray ) and c .dtype .kind in "if" and
216
+ c .ndim == 2 and c .shape [1 ] in [3 , 4 ]):
216
217
if c .shape [1 ] == 3 :
217
218
result = np .column_stack ([c , np .zeros (len (c ))])
218
219
result [:, - 1 ] = alpha if alpha is not None else 1.
@@ -230,10 +231,10 @@ def to_rgba_array(c, alpha=None):
230
231
return result
231
232
232
233
233
- def to_rgb (c ):
234
+ def to_rgb (c , prop_cycler = None ):
234
235
"""Convert `c` to an RGB color, silently dropping the alpha channel.
235
236
"""
236
- return to_rgba (c )[:3 ]
237
+ return to_rgba (c , prop_cycler = prop_cycler )[:3 ]
237
238
238
239
239
240
def to_hex (c , keep_alpha = False ):
@@ -248,8 +249,7 @@ def to_hex(c, keep_alpha=False):
248
249
return "#" + "" .join (format (int (np .round (val * 255 )), "02x" )
249
250
for val in c )
250
251
251
-
252
- ### Backwards-compatible color-conversion API
252
+ # ## Backwards-compatible color-conversion API
253
253
254
254
cnames = CSS4_COLORS
255
255
COLOR_NAMES = {'xkcd' : XKCD_COLORS , 'css4' : CSS4_COLORS }
0 commit comments