Skip to content

Fix legend edgecolor face #20260

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
wants to merge 3 commits into from

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented May 18, 2021

PR Summary

Closes #20258

Passing 'face' to a polygon that would show up in the legend would not be recognized. Now it is...

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.fill_between([0, 1, 2], [1, 2, 3], [2, 3, 4], 
                facecolor='r', edgecolor='face', label='Fill')
ax.legend()
plt.show()

before:

ValueError: Using a string of single character colors as a color sequence is not supported. The colors can be passed as an explicit list instead.

Now:

face

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • 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).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@jklymak jklymak added this to the v3.4.3 milestone May 18, 2021
@jklymak jklymak force-pushed the fix-legend-edgecolor-face branch from 55c24d1 to 1cb7a78 Compare May 18, 2021 20:56
@@ -749,6 +749,9 @@ def get_first(prop_array):
return None
edgecolor = getattr(orig_handle, '_original_edgecolor',
orig_handle.get_edgecolor())
if edgecolor == 'face':
Copy link
Member Author

Choose a reason for hiding this comment

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

Note we can't just get rid of the line before as it causes some hatching tests to fail for some reason...

@efiring
Copy link
Member

efiring commented May 18, 2021

#8575 put in the mysterious fix for the hatching. Strangely, although edgecolor="face" was failing, edgecolor="none" was not.

@jklymak
Copy link
Member Author

jklymak commented May 18, 2021

Thanks - we could also do

edgecolor = orig_handle.get_edgecolor()
if isempty(edgecolor):
   edgecolor = None;

Or fix it in collections.py:get_edgecolor

@jklymak
Copy link
Member Author

jklymak commented May 18, 2021

Third commit checks for no colors...

efiring added a commit to efiring/matplotlib that referenced this pull request May 19, 2021
efiring added a commit to efiring/matplotlib that referenced this pull request May 19, 2021
@efiring efiring mentioned this pull request May 19, 2021
5 tasks
@jklymak
Copy link
Member Author

jklymak commented May 19, 2021

Close in favour of #20265

@jklymak jklymak closed this May 19, 2021
@jklymak jklymak deleted the fix-legend-edgecolor-face branch May 19, 2021 23:55
jklymak pushed a commit to jklymak/matplotlib that referenced this pull request Jun 13, 2021
jklymak pushed a commit to jklymak/matplotlib that referenced this pull request Jun 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using edgecolors='face' with stackplot causes value error when using plt.legend()
2 participants