Skip to content

Passing an incorrectly sized colour list to scatter should raise a relevant error #9209

Closed
@MatthewJA

Description

@MatthewJA

If the length of the c argument to matplotlib.pyplot.scatter doesn't match the size of the x and y arguments, a confusing error message is raised: Invalid RGBA argument. Contrast this with the error that results if x and y are not the same size: x and y must be the same size. The error message for an incorrect size c array should be made more clear.

Code for reproduction

import numpy, matplotlib.pyplot as plt
xs, ys = numpy.random.random((2, 10))
c = numpy.random.random(9)
plt.scatter(xs, ys, c=c)

Actual outcome

/usr/local/lib/python3.6/site-packages/matplotlib/colors.py in _to_rgba_no_colorcycle(c, alpha)
    192         # float)` and `np.array(...).astype(float)` all convert "0.5" to 0.5.
    193         # Test dimensionality to reject single floats.
--> 194         raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
    195     # Return a tuple to prevent the cached value from being modified.
    196     c = tuple(c.astype(float))

ValueError: Invalid RGBA argument: 0.58430716187559439

Expected outcome

ValueError: c and x must be the same size
  • Matplotlib Version: 2.0.2
  • Python Version: 3.6.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions