Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
Milestone
@landoskape

Description

@landoskape

Bug summary

Inmatplotlib.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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp