@@ -152,7 +152,7 @@ def to_rgba(c, alpha=None):
152152
153153 Parameters
154154 ----------
155- c : Matplotlib color
155+ c : Matplotlib color or ``np.ma.masked``
156156
157157 alpha : scalar, optional
158158 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):
189189 ``"none"`` (case-insensitive), which always maps to ``(0, 0, 0, 0)``.
190190 """
191191 orig_c = c
192+ if c is np .ma .masked :
193+ return (0. , 0. , 0. , 0. )
192194 if isinstance (c , str ):
193195 if c .lower () == "none" :
194196 return (0. , 0. , 0. , 0. )
@@ -260,19 +262,25 @@ def to_rgba_array(c, alpha=None):
260262
261263 If *alpha* is not ``None``, it forces the alpha value. If *c* is
262264 ``"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*.
263267 """
264268 # Special-case inputs that are already arrays, for performance. (If the
265269 # array has the wrong kind or shape, raise the error during one-at-a-time
266270 # conversion.)
267271 if (isinstance (c , np .ndarray ) and c .dtype .kind in "if"
268272 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 )
269275 if c .shape [1 ] == 3 :
270276 result = np .column_stack ([c , np .zeros (len (c ))])
271277 result [:, - 1 ] = alpha if alpha is not None else 1.
272278 elif c .shape [1 ] == 4 :
273279 result = c .copy ()
274280 if alpha is not None :
275281 result [:, - 1 ] = alpha
282+ if mask is not None :
283+ result [mask ] = 0
276284 if np .any ((result < 0 ) | (result > 1 )):
277285 raise ValueError ("RGBA values should be within 0-1 range" )
278286 return result
0 commit comments