MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / to_rgba

Function to_rgba

lib/matplotlib/colors.py:306–350  ·  view source on GitHub ↗

Convert *c* to an RGBA color. Parameters ---------- c : :mpltype:`color` or ``np.ma.masked`` alpha : float, optional If *alpha* is given, force the alpha value of the returned RGBA tuple to *alpha*. If None, the alpha value from *c* is used. If *c* doe

(c, alpha=None)

Source from the content-addressed store, hash-verified

304
305
306def to_rgba(c, alpha=None):
307 """
308 Convert *c* to an RGBA color.
309
310 Parameters
311 ----------
312 c : :mpltype:`color` or ``np.ma.masked``
313
314 alpha : float, optional
315 If *alpha* is given, force the alpha value of the returned RGBA tuple
316 to *alpha*.
317
318 If None, the alpha value from *c* is used. If *c* does not have an
319 alpha channel, then alpha defaults to 1.
320
321 *alpha* is ignored for the color value ``"none"`` (case-insensitive),
322 which always maps to ``(0, 0, 0, 0)``.
323
324 Returns
325 -------
326 tuple
327 Tuple of floats ``(r, g, b, a)``, where each channel (red, green, blue,
328 alpha) can assume values between 0 and 1.
329 """
330 if isinstance(c, tuple) and len(c) == 2:
331 if alpha is None:
332 c, alpha = c
333 else:
334 c = c[0]
335 # Special-case nth color syntax because it should not be cached.
336 if _is_nth_color(c):
337 prop_cycler = mpl.rcParams['axes.prop_cycle']
338 colors = prop_cycler.by_key().get('color', ['k'])
339 c = colors[int(c[1:]) % len(colors)]
340 try:
341 rgba = _colors_full_map.cache[c, alpha]
342 except (KeyError, TypeError): # Not in cache, or unhashable.
343 rgba = None
344 if rgba is None: # Suppress exception chaining of cache lookup failure.
345 rgba = _to_rgba_no_colorcycle(c, alpha)
346 try:
347 _colors_full_map.cache[c, alpha] = rgba
348 except TypeError:
349 pass
350 return rgba
351
352
353def _to_rgba_no_colorcycle(c, alpha=None):

Callers 9

registerMethod · 0.85
is_color_likeFunction · 0.85
to_rgba_arrayFunction · 0.85
to_rgbFunction · 0.85
to_hexFunction · 0.85
__init__Method · 0.85
_set_extremesMethod · 0.85
with_extremesMethod · 0.85
with_extremesMethod · 0.85

Calls 3

_is_nth_colorFunction · 0.85
_to_rgba_no_colorcycleFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…