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

Skip to content

[Bug]: The method for checking whether a color has an alpha value is outdated #27321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
landoskape opened this issue Nov 14, 2023 · 2 comments · Fixed by #27327
Closed

[Bug]: The method for checking whether a color has an alpha value is outdated #27321

landoskape opened this issue Nov 14, 2023 · 2 comments · Fixed by #27327
Milestone

Comments

@landoskape
Copy link
Contributor

landoskape commented Nov 14, 2023

Bug summary

In matplotlib.colors._has_alpha_channel, it fails to identify colors with alpha channels in two contexts.

  1. 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.
  2. 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

import matplotlib.colors as mcolors

color = '#0f0f0f80'
print(mcolors._has_alpha_channel(color))

color = ('r', 0.5)
print(mcolors._has_alpha_channel(color))

Actual outcome

False
False

Expected outcome

True
True

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

@raunak-sood2003
Copy link

raunak-sood2003 commented Dec 3, 2023

@landoskape Is this still an issue? If so, could I be assigned to it?

@rcomer
Copy link
Member

rcomer commented Dec 3, 2023

This issue already has a linked pull request, and anyway we do not assign them. Please see our contributors’ guide:
https://matplotlib.org/devdocs/devel/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants