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

Skip to content

Set the axes of legend text #20458

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
Jun 17, 2021
Merged

Set the axes of legend text #20458

merged 1 commit into from
Jun 17, 2021

Conversation

dstansby
Copy link
Member

PR Summary

Previously the text added in a legend had .axes == None. Fixes #20435

Not sure if this needs a changelog entry?

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).

@@ -743,6 +743,7 @@ def _init_legend_box(self, handles, labels, markerfirst=True):
label_prop = dict(verticalalignment='baseline',
horizontalalignment='left',
fontproperties=self.prop,
axes=self.axes
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 that is one soon. However, why doesn't it get set when the artist is added to the axes?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated it to set the axes of ._legend_box, which automatically sets the axes of its children. I think this is more general solution?

Copy link
Member

Choose a reason for hiding this comment

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

That sounds better!

@tacaswell tacaswell added this to the v3.5.0 milestone Jun 17, 2021
@tacaswell
Copy link
Member

What does this do in the case of figure level legends?

@dstansby
Copy link
Member Author

What does this do in the case of figure level legends?

Legend.axes == None, which propagates down to setting the .axes property to None on the artists, which seems to be the default value for an artist not attached to an Axes.

@tacaswell tacaswell merged commit 9ee6ff5 into matplotlib:master Jun 17, 2021
@dstansby dstansby deleted the leg-text branch June 17, 2021 17:53
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.

Legend Text's axes attribute is None
3 participants