Skip to content

Wrong Error Message #11919

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
davidleejy opened this issue Aug 23, 2018 · 3 comments
Closed

Wrong Error Message #11919

davidleejy opened this issue Aug 23, 2018 · 3 comments

Comments

@davidleejy
Copy link

davidleejy commented Aug 23, 2018

Bug report

Affects: commit 7b5ff33 (master, 23 Aug 2018)

An attempt to plot a single point at coords (2,3) with RGB color (120,130,140) throws an error message remarking about argument shapes mismatching. Message should be about RGB values outside range 0 to 1.

Code for reproduction

ax.scatter(np.array([2]), np.array([3]), c=np.array([[120,130,140]]))
ValueError: c of shape (1, 3) not acceptable as a color sequence for x with size 1, y with size 1

This is ok:

ax.scatter(np.array([2]), np.array([3]), c=np.array([[120,130,140]]) / 255.0 )

Actual outcome

See above.

Expected outcome

Suggestion: error message could be about RGB values outside of 0 to 1 range.

Trace

  File "/home/d/code/matplotlib/lib/matplotlib/axes/_axes.py", line 4223, in scatter
    .format(nc=n_elem, xs=x.size, ys=y.size)
ValueError: 'c' argument has 3 elements, which is not acceptable for use with 'x' with size 1, 'y' with size 1.

python 2 gives slightly different trace:

/home/d/.conda/envs/py2_dp/lib/python2.7/site-packages/matplotlib-2.2.2-py2.7-linux-x86_64.egg/matplotlib/axes/_axes.pyc in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
   4277                 raise ValueError("c of shape {} not acceptable as a color "
   4278                                  "sequence for x with size {}, y with size {}"
-> 4279                                  .format(c.shape, x.size, y.size))
   4280         else:
   4281             colors = None  # use cmap, norm after collection is created

ValueError: c of shape (1, 3) not acceptable as a color sequence for x with size 1, y with size 1

Matplotlib version

  • Operating system: Ubuntu 16.04
  • Matplotlib version: commit 7b5ff33 (master, 23 Aug 2018)
  • Matplotlib backend (print(matplotlib.get_backend())): <object object at 0x7f8885d87190>
  • Python version: 3.5.5
  • Jupyter version (if applicable): none
  • Other libraries: numpy

How I installed matplotlib:

  1. Create new conda env with python 3.5.5
  2. git clone matplotlib master
  3. pip install -e /path/to/cloned-repo
@afvincent
Copy link
Contributor

@davidleejy Thank you for the extensive ticket :).

FTR, the difference between Python 2 and 3 is “simply” related to #11383.

@anntzer
Copy link
Contributor

anntzer commented Jun 24, 2019

For the better or the worst (mostly the worst, IMO, but see discussion in #12735), the error message is also correct, because c could be colormapped data (and x/y could indeed have been badly sized): something like

scatter(np.array([[0, 1, 2]]), np.array([[0, 1, 2]]), c=np.array([[120, 130, 140]]))

works.

Note that as of master, the exception is

Traceback (most recent call last):
  <elided>
ValueError: RGBA values should be within 0-1 range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  <elided>
ValueError: 'c' argument has 3 elements, which is inconsistent with 'x' and 'y' with size 1.

which seems not too bad, so I'm suggesting to close this.

@efiring
Copy link
Member

efiring commented Jul 5, 2019

Closing as suggested by @anntzer

@efiring efiring closed this as completed Jul 5, 2019
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.

5 participants