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

Skip to content

FIX: correctly handle ax.legend(..., legendcolor='none') #20225

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

Merged
merged 1 commit into from
May 15, 2021

Conversation

tacaswell
Copy link
Member

PR Summary

Previously this would result in the label color being ignored because
colors.to_rgba_array('none') results in a 0 length array which in turn has
a 0 length cycle, which results in the zip over texts and colors terminating
before we have touched any of the texts, ignoring the color.

This makes::

 ax.legend(..., legendcolor='none')
 ax.legend(..., legendcolor=['none'])

behave the same

Discovered this while reviewing #20084 and trying to demonstrate the difference between None and 'none' in our color conventions.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • [N/A] New features are documented, with examples if plot related.
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

Previously this would result in the label color being ignored because
colors.to_rgba_array('none') results in a 0 length array which in turn has
a 0 length cycle, which results in the zip over texts and colors terminating
before we have touched any of the texts, ignoring the color.

This makes::

     ax.legend(..., legendcolor='none')
     ax.legend(..., legendcolor=['none'])

behave the same
@tacaswell tacaswell added this to the v3.4.3 milestone May 14, 2021
@@ -550,6 +550,9 @@ def __init__(self, parent, handles, labels,
break
except AttributeError:
pass
elif isinstance(labelcolor, str) and labelcolor == 'none':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I'd have thought these were redundant....

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a numpy array come is than elif obj == "none": gets us the "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()" issue.

I thought about merging this with the conditional above, but was trying to avoid causing a rebase for @Carloscerq in #20084.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don’t worry about it. I think I can handle it over the weekend, and, if it’s the case, I can remake the #20084 .

@QuLogic QuLogic merged commit c50a374 into matplotlib:master May 15, 2021
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request May 15, 2021
QuLogic added a commit that referenced this pull request May 15, 2021
…225-on-v3.4.x

Backport PR #20225 on branch v3.4.x (FIX: correctly handle ax.legend(..., legendcolor='none'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants