Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug summary
Inmatplotlib.colors._has_alpha_channel, it fails to identify colors with alpha channels in two contexts.
- It assumes that any color specified as a string doesn't have an alpha channel. This is outdated, because hex strings that contain alpha values are permitted.
- It assumes that tuples indicating the color and the alpha don't have alpha channels. This is because it assumes that the length has to be 4 for a non-string with an alpha channel.
Code for reproduction
importmatplotlib.colorsasmcolorscolor='#0f0f0f80'print(mcolors._has_alpha_channel(color))color= ('r',0.5)print(mcolors._has_alpha_channel(color))
Actual outcome
FalseFalse
Expected outcome
TrueTrue
Additional information
I can imagine a few fixes, but the code for creating an RGBA array from a color is a bit opaque to me. Also, the method is currently only used in lib/matplotlib/axis.py for the Tick class and in lib/matplotlib/test_colors.py. So maybe it's not that important, but it could be more useful if more flexible and accurate.
Motivation:
The motivation for this bug issue is the context where the alpha value should be set to a default value if the alpha is not provided by the user. This context would benefit greatly from a method that accurately determines whether a color or a sequence of colors have alpha values.
Operating system
OS/X
Matplotlib Version
3.9.0.dev687+g4099a45ee5
Matplotlib Backend
MacOSX
Python version
3.10.12
Jupyter version
No response
Installation
None