@@ -152,7 +152,7 @@ def to_rgba(c, alpha=None):
152
152
153
153
Parameters
154
154
----------
155
- c : Matplotlib color
155
+ c : Matplotlib color or ``np.ma.masked``
156
156
157
157
alpha : scalar, optional
158
158
If *alpha* is not ``None``, it forces the alpha value, except if *c* is
@@ -189,6 +189,8 @@ def _to_rgba_no_colorcycle(c, alpha=None):
189
189
``"none"`` (case-insensitive), which always maps to ``(0, 0, 0, 0)``.
190
190
"""
191
191
orig_c = c
192
+ if c is np .ma .masked :
193
+ return (0. , 0. , 0. , 0. )
192
194
if isinstance (c , str ):
193
195
if c .lower () == "none" :
194
196
return (0. , 0. , 0. , 0. )
@@ -260,19 +262,25 @@ def to_rgba_array(c, alpha=None):
260
262
261
263
If *alpha* is not ``None``, it forces the alpha value. If *c* is
262
264
``"none"`` (case-insensitive) or an empty list, an empty array is returned.
265
+ If *c* is a masked array, an ndarray is returned with a (0, 0, 0, 0)
266
+ row for each masked value or row in *c*.
263
267
"""
264
268
# Special-case inputs that are already arrays, for performance. (If the
265
269
# array has the wrong kind or shape, raise the error during one-at-a-time
266
270
# conversion.)
267
271
if (isinstance (c , np .ndarray ) and c .dtype .kind in "if"
268
272
and c .ndim == 2 and c .shape [1 ] in [3 , 4 ]):
273
+ mask = c .mask .any (axis = 1 ) if np .ma .is_masked (c ) else None
274
+ c = np .ma .getdata (c )
269
275
if c .shape [1 ] == 3 :
270
276
result = np .column_stack ([c , np .zeros (len (c ))])
271
277
result [:, - 1 ] = alpha if alpha is not None else 1.
272
278
elif c .shape [1 ] == 4 :
273
279
result = c .copy ()
274
280
if alpha is not None :
275
281
result [:, - 1 ] = alpha
282
+ if mask is not None :
283
+ result [mask ] = 0
276
284
if np .any ((result < 0 ) | (result > 1 )):
277
285
raise ValueError ("RGBA values should be within 0-1 range" )
278
286
return result
0 commit comments