Skip to content

Unhelpful ValueError raised when color array is incorrect format #15727

Closed
@TTitcombe

Description

@TTitcombe

Bug report

Bug summary
When colors passed to a plot are provided as tuples in the range [0, 255] instead of [0, 1], the error raised relates to the shape of the data (which is correct), not the values of the data.

Code for reproduction

import matplotlib.pyplot as plt

plt.scatter([0, 1], [0, 1], c=[(255, 0, 0), (0, 255, 0)])

Actual outcome

ValueError: 'c' argument has 2 elements, which is not acceptable for use with 'x' with size 2, 'y' with size 2.

Edit:

ValueError: RGBA values should be within 0-1 range

is also raised, however it is less prominent than the "size" error, which should not be raised at all

Expected outcome
A single, specific error message:

ValueError: RGBA values should be within 0-1 range

Matplotlib version

  • Operating system: Windows 10
  • Matplotlib version: 3.1.2
  • Matplotlib backend: Qt5Agg
  • Python version: 3.7.3

Installed matplotlib from conda

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions