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]: colors.LinearSegmentedColormap.from_list does not take two tuples in 3.8.0 #26949

Closed
@dave-shirley-faraday

Description

@dave-shirley-faraday

Bug summary

Incrementing from v3.7 to v3.8 the option to specify a start and end value is no longer functioning when two values are specified. It still works when three are specified.

## This works:matplotlib.colors.LinearSegmentedColormap.from_list("myMap", ["#000000", "#FFFFFF"])
## This does not:matplotlib.colors.LinearSegmentedColormap.from_list("myMap", [(0,"#000000"), (1,"#FFFFFF")])

Code for reproduction

matplotlib.colors.LinearSegmentedColormap.from_list("myMap", [(0,"#000000"), (1,"#FFFFFF")])

Actual outcome

Traceback (most recent call last):
File "", line 1, in
File "/Users/dave/.local/share/virtualenvs/projects-t0xU6-ce/lib/python3.10/site-packages/matplotlib/colors.py", line 1065, in from_list
colors : array-like of colors or array-like of (value, color)
File "/Users/dave/.local/share/virtualenvs/projects-t0xU6-ce/lib/python3.10/site-packages/matplotlib/colors.py", line 489, in to_rgba_array
pass
ValueError: '#000000' is not a valid color value.

Expected outcome

<matplotlib.colors.LinearSegmentedColormap object at 0x101e7f520>

Additional information

Worked in 3.7

The issue I think is related to zipped values being passed tor, g, b, a = to_rgba_array(colors).T. A tuple gets passed in rather than a list.

## tuple len 2 fails>>> matplotlib.colors.to_rgba_array(("#000000", "#FFFFFF"))Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/Users/dave/.local/share/virtualenvs/model_train-t0xU6-ce/lib/python3.10/site-packages/matplotlib/colors.py", line 489, in to_rgba_array    passValueError: '#000000' is not a valid color value.## list works>>> matplotlib.colors.to_rgba_array(["#000000", "#FFFFFF"])array([[0., 0., 0., 1.],       [1., 1., 1., 1.]])

Changingr, g, b, a = to_rgba_array(colors).T incolors.py:LinearSegmentedColormap.from_list tor, g, b, a = to_rgba_array(list(colors)).T or similar may fix.

Operating system

OS/X

Matplotlib Version

3.8.0

Matplotlib Backend

MacOSX

Python version

Python 3.10.9

Jupyter version

No response

Installation

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp