Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e97af0

Browse files
timhoffmstory645
andcommitted
Improve docs for rgba conversion
Co-authored-by: hannah <[email protected]>
1 parent 71c9f09 commit 9e97af0

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

lib/matplotlib/colors.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,20 @@ 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 *alpha* is given, force the alpha value of the returned RGBA tuple
188+
to *alpha*.
189+
190+
If None, the alpha value from *c* is used. If *c* does not have an
191+
alpha channel, then alpha defaults to 1.
192+
193+
*alpha* is ignored for the color value ``"none"`` (case-insensitive),
194+
which always maps to ``(0, 0, 0, 0)``.
189195
190196
Returns
191197
-------
192198
tuple
193-
Tuple of ``(r, g, b, a)`` scalars.
199+
Tuple of floats ``(r, g, b, a)``, where each channel (red, green, blue,
200+
alpha) can assume values between 0 and 1.
194201
"""
195202
# Special-case nth color syntax because it should not be cached.
196203
if _is_nth_color(c):
@@ -215,8 +222,12 @@ def _to_rgba_no_colorcycle(c, alpha=None):
215222
"""
216223
Convert *c* to an RGBA color, with no support for color-cycle syntax.
217224
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)``.
225+
If *alpha* is given, force the alpha value of the returned RGBA tuple
226+
to *alpha*. Otherwise, the alpha value from *c* is used, if it has alpha
227+
information, or defaults to 1.
228+
229+
*alpha* is ignored for the color value ``"none"`` (case-insensitive),
230+
which always maps to ``(0, 0, 0, 0)``.
220231
"""
221232
orig_c = c
222233
if c is np.ma.masked:
@@ -310,16 +321,23 @@ def to_rgba_array(c, alpha=None):
310321
row for each masked value or row in *c*.
311322
312323
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)``.
324+
If *alpha* is given, force the alpha value of the returned RGBA tuple
325+
to *alpha*.
326+
327+
If None, the alpha value from *c* is used. If *c* does not have an
328+
alpha channel, then alpha defaults to 1.
329+
330+
*alpha* is ignored for the color value ``"none"`` (case-insensitive),
331+
which always maps to ``(0, 0, 0, 0)``.
332+
315333
If *alpha* is a sequence and *c* is a single color, *c* will be
316334
repeated to match the length of *alpha*.
317335
318336
Returns
319337
-------
320338
array
321-
(n, 4) array of RGBA colors.
322-
339+
(n, 4) array of RGBA colors, where each channel (red, green, blue,
340+
alpha) can assume values between 0 and 1.
323341
"""
324342
# Special-case inputs that are already arrays, for performance. (If the
325343
# array has the wrong kind or shape, raise the error during one-at-a-time

0 commit comments

Comments
 (0)