Skip to content

[Bug]: color=("Cn", alpha) does not work #27827

Closed

Description

@anntzer

Bug summary

Reading https://matplotlib.org/stable/users/explain/colors/colors.html#color-formats it would seem like color=("C0", .5) (C0 color with alpha=0.5) should work, but it doesn't.

(Could also be considered a doc bug or a feature request, strictly speaking.)

Code for reproduction

from pylab import *; plot([0, 1], c=("C0", .5))

Actual outcome

ValueError: ('C0', 0.5) is not a valid value for color

Expected outcome

No error.

Additional information

No response

Operating system

macos

Matplotlib Version

3.9.0.dev1178+g88d64e5f0c

Matplotlib Backend

any

Python version

3.12

Jupyter version

none

Installation

git checkout

Activity

  1. ksunden commented on Feb 27, 2024

    @ksunden
    Member

    the precise logic that parses 2-element tuples into color/alpha is:

    if isinstance(c, tuple) and len(c) == 2:
    if alpha is None:
    c, alpha = c
    else:
    c = c[0]

    This appears in the private function _to_rgba_no_colorcycle. This function is only ever called from to_rgba (after handling the Cn case specially). Moving (or adding, I guess) the same lines to the beginning of the public to_rgba would allow ("C0", 0.5) and likely not have too many other repercussions.

  2. FilBalza commented on Jul 14, 2024

    @FilBalza
    Contributor

    When trying to solve this issue, I saw that the suggested solution was already added and the code now works. Here's the commit for reference: 13b8718

  3. added this to the v3.9.1 milestone on Jul 14, 2024
  4. rcomer commented on Jul 14, 2024

    @rcomer
    Member

    Fixed by #28436

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions