Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unhelpful ValueError raised when color array is incorrect format #15727

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
TTitcombe opened this issue Nov 19, 2019 · 3 comments
Closed

Unhelpful ValueError raised when color array is incorrect format #15727

TTitcombe opened this issue Nov 19, 2019 · 3 comments

Comments

@TTitcombe
Copy link

TTitcombe commented Nov 19, 2019

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

@TTitcombe
Copy link
Author

TTitcombe commented Nov 20, 2019

The correct error is being raised from colors = mcolors.to_rgba_array(c) in _axes.py. However, this is caught in _axes.py and the incorrect ValueError is raised here.

The incorrect error is raised because valid_shape is False, which is being set here. This is caused by c.size == xsize evaluating to False when c is an array of tuples because c.size will be number of tuple X size of tuple, so for c=[(255, 0, 0), (0, 255, 0)], c.size == 6 when that statement is intended to check if it is 2.

I haven't had the time to work out exactly what the intention of this bit of the code is, so have not yet found a solution.

@github-actions
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jun 30, 2023
@QuLogic
Copy link
Member

QuLogic commented Jun 30, 2023

This was fixed by #17245 in 3.3.0.

@QuLogic QuLogic closed this as completed Jun 30, 2023
@QuLogic QuLogic removed the status: inactive Marked by the “Stale” Github Action label Jun 30, 2023
@QuLogic QuLogic added this to the v3.3.0 milestone Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants