8000 Improve docs for rgba conversion · matplotlib/matplotlib@226bda3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 226bda3

Browse files
committed
Improve docs for rgba conversion
1 parent 71c9f09 commit 226bda3

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

lib/matplotlib/colors.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,19 @@ def to_rgba(c, alpha=None):
184184
c : Matplotlib color or ``np.ma.masked``
185185
186186
alpha : float, optional
187-
If *alpha* is not ``None``, it forces the alpha value, except if *c* is
188-
``"none"`` (case-insensitive), which always maps to ``(0, 0, 0, 0)``.
187+
If given, force the alpha value of the returned RGBA tuple to *alpha*.
188+
189+
If None, the alpha value from *c* is used, if it has alpha information,
190+
or default to 1.
191+
192+
*alpha* is ignored for the color value ``"none"`` (case-insensitive),
193+
which always maps to ``(0, 0, 0, 0)``.
189194
190195
Returns
191196
-------
192197
tuple
193-
Tuple of ``(r, g, b, a)`` scalars.
198+
Tuple of floats ``(r, g, b, a)``, where each channel (red, green, blue,
199+
alpha) can assume values between 0 and 1.
194200
"""
195201
# Special-case nth color syntax because it should not be cached.
196202
if _is_nth_color(c):
@@ -215,8 +221,12 @@ def _to_rgba_no_colorcycle(c, alpha=None):
215221
"""
216222
Convert *c* to an RGBA color, with no support for color-cycle syntax.
217223
218-
If *alpha* is not ``None``, it forces the alpha value, except if *c* is
219-
``"none"`` (case-insensitive), which always maps to ``(0, 0, 0, 0)``.
224+
IF *alpha* is given, force the alpha value of the returned RGBA tuple
225+
to *alpha*. Otherwise, the alpha value from *c* is used, if it has alpha
226+
information, or default to 1.
227+
228+
*alpha* is ignored for the color value ``"none"`` (case-insensitive),
229+
which always maps to ``(0, 0, 0, 0)``.
220230
"""
221231
orig_c = c
222232
if c is np.ma.masked:
@@ -310,16 +320,22 @@ def to_rgba_array(c, alpha=None):
310320
row for each masked value or row in *c*.
311321
312322
alpha : float or sequence of floats, optional
313-
If *alpha* is not ``None``, it forces the alpha value, except if *c* is
314-
``"none"`` (case-insensitive), which always maps to ``(0, 0, 0, 0)``.
323+
If given, force the alpha value of the returned RGBA tuple to *alpha*.
324+
325+
If None, the alpha value from *c* is used, if it has alpha information,
326+
or default to 1.
327+
328+
*alpha* is ignored for the color value ``"none"`` (case-insensitive),
329+
which always maps to ``(0, 0, 0, 0)``.
330+
315331
If *alpha* is a sequence and *c* is a single color, *c* will be
316332
repeated to match the length of *alpha*.
317333
318334
Returns
319335
-------
320336
array
321-
(n, 4) array of RGBA colors.
322-
337+
(n, 4) array of RGBA colors, where each channel (red, green, blue,
338+
alpha) can assume values between 0 and 1.
323339
"""
324340
# Special-case inputs that are already arrays, for performance. (If the
325341
# array has the wrong kind or shape, raise the error during one-at-a-time

0 commit comments

Comments
 (0)
0