Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Legend guide addition#24707

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
matthewelmer wants to merge4 commits intomatplotlib:mainfrommatthewelmer:legend-guide-addition
Closed

Legend guide addition#24707

matthewelmer wants to merge4 commits intomatplotlib:mainfrommatthewelmer:legend-guide-addition

Conversation

matthewelmer
Copy link

@matthewelmermatthewelmer commentedDec 12, 2022
edited
Loading

PR Summary

This pull request adds an example to the legend guide. While the legend guide already has a nice way of putting a legend above a subplot, it didn't have an example showing how to do a common legend above multiple subplots. I found a pretty good way to do it, and I wanted to share!

PR Checklist

Documentation and Tests

  • [N/A] Has pytest style unit tests (andpytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • [N/A] New plotting related features are documented with examples.

Release Notes

  • New features are marked with a.. versionadded:: directive in the docstring and documented indoc/users/next_whats_new/
  • API changes are marked with a.. versionchanged:: directive in the docstring and documented indoc/api/next_api_changes/
  • Release notes conform with instructions innext_whats_new/README.rst ornext_api_changes/README.rst

@matthewelmer
Copy link
Author

Ah, shoot. I didn't check indentation. Sorry about that.

Copy link

@github-actionsgithub-actionsbot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping@matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join uson gitter for real-time discussion.

For details on testing, writing docs, and our review process, please seethe developer guide

We strive to be a welcoming and open project. Please follow ourCode of Conduct.

@rcomer
Copy link
Member

rcomer commentedDec 22, 2022
edited
Loading

Hi@matthewelmer, thanks for the proposal. This is a neat solution for getting the legend nicely placed with current Matplotlib capability. However, you may be interested in the proposed new functionality at#19743. I think this will allow users to get the desired layout more simply:

importnumpyasnpimportmatplotlib.pyplotaspltfig,axes=plt.subplots(1,3,layout="constrained")eta=np.linspace(0,1)cap_lambda_vals=np.array([-24,-12,0,12,24])forcap_lambdaincap_lambda_vals:# Some dataf=2*eta-2*eta**3+eta**4+cap_lambda*eta/6* (1-eta)**3df_deta=2-6*eta**2+4*eta**3+cap_lambda/ \6* (1-6*eta+9*eta**2-4*eta**3)d2f_deta2=-12*eta+12*eta**2+ \cap_lambda/6* (-6+18*eta-12*eta**2)# Plot dataaxes[0].plot(f,eta,label=f"$\Lambda ={cap_lambda}$")axes[1].plot(df_deta,eta,label=f"$\Lambda ={cap_lambda}$")axes[2].plot(d2f_deta2,eta,label=f"$\Lambda ={cap_lambda}$")# Add a legend to the figure, using the handles from the plot you want to# create the legend for.fig.legend(loc="outside upper center",ncol=len(cap_lambda_vals),handles=axes[0].get_legend_handles_labels()[0],mode="expand")plt.show()

temp

@matthewelmer
Copy link
Author

That's great! Thank you for bringing this to my attention. I'm happy to hear that a feature I have wanted for so long is being implemented!

rcomer reacted with thumbs up emoji

@matthewelmermatthewelmer deleted the legend-guide-addition branchJanuary 2, 2023 12:17
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

Assignees
No one assigned
Labels
None yet
Projects
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@matthewelmer@rcomer

[8]ページ先頭

©2009-2025 Movatter.jp