Skip to content

Misleading error message in _parse_scatter_color_args #17243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
orrkrup opened this issue Apr 25, 2020 · 0 comments · Fixed by #17245
Closed

Misleading error message in _parse_scatter_color_args #17243

orrkrup opened this issue Apr 25, 2020 · 0 comments · Fixed by #17245

Comments

@orrkrup
Copy link

orrkrup commented Apr 25, 2020

Bug report

Not really a bug, just an annoying error message.
In _axes.py, line 4283, the try clause catches errors in an unintended section of code and adds an error message that doesn't make sense to the traceback. For instance, if a ValueError is raised in the call to to_rgb_array(c), it will be caught and the error would be wrong.

Code for reproduction:

import matplotlib.pyplot as plt
import numpy as np

a = np.arange(10)
b = np.random.rand(10)
colors = np.random.rand(10, 3) * 2.0

plt.scatter(a, b, c=colors)

This results in the following traceback:

Traceback (most recent call last):
  File "/Users/user/lib/python3.6/site-packages/matplotlib/axes/_axes.py", line 4284, in _parse_scatter_color_args
    colors = mcolors.to_rgba_array(c)
  File "/Users/user/lib/python3.6/site-packages/matplotlib/colors.py", line 279, in to_rgba_array
    raise ValueError("RGBA values should be within 0-1 range")
ValueError: RGBA values should be within 0-1 range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/user/lib/python3.6/site-packages/matplotlib/pyplot.py", line 2841, in scatter
    None else {}), **kwargs)
  File "/Users/user/lib/python3.6/site-packages/matplotlib/__init__.py", line 1599, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/Users/user/lib/python3.6/site-packages/matplotlib/axes/_axes.py", line 4453, in scatter
    get_next_color_func=self._get_patches_for_fill.get_next_color)
  File "/Users/user/lib/python3.6/site-packages/matplotlib/axes/_axes.py", line 4297, in _parse_scatter_color_args
    .format(nc=n_elem, xs=xsize, ys=ysize)
ValueError: 'c' argument has 10 elements, which is not acceptable for use with 'x' with size 10, 'y' with size 10.

The first part of the traceback makes sense, but the last error message shouldn't be there, especially since it states something that is not true (number of elements is acceptable).

Matplotlib version

  • Operating system: MacOS 10.15.3
  • Matplotlib version: 3.1.2
  • Matplotlib backend: MacOSX
  • Python version: 3.6.8

Thanks!

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

Successfully merging a pull request may close this issue.

2 participants