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

savefig's pad_inches specifies per border padding#30183

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

Open
ttshaw1 wants to merge5 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromttshaw1:main

Conversation

ttshaw1
Copy link

@ttshaw1ttshaw1 commentedJun 17, 2025
edited
Loading

Added a new padding function to transforms.py, called it in backend_bases, and updated documentation where pad_inches shows up

PR summary

Solution for#11764, allowing pad_inches to be set for each border when saving a figure.

  • Why is this change necessary?
    Difficult to get compact but suitably bounding borders in savefig with extra artists in some cases
  • What problem does it solve?
    E.g. a plot with broken axes made with subfigures and diagonal lines indicating the break is hard to bound correctly. This adds a crude but simple way to modify the bounding box as needed.
  • What is the reasoning for this implementation?
    Seems like the simplest way to do it.
import matplotlib.pyplot as pltimport numpy as npplt.plot(np.arange(1, 10))plt.xlabel('Test')plt.ylabel('Test2')plt.title('Typical Title')plt.savefig('test_float_0.png', bbox_inches = 'tight', pad_inches = 0)plt.savefig('test_tuple_0.png', bbox_inches = 'tight', pad_inches = [0, 0, 0, 0])plt.savefig('test_float_1.png', bbox_inches = 'tight', pad_inches = 1)plt.savefig('test_tuple_1.png', bbox_inches = 'tight', pad_inches = [1, 1, 1, 1])plt.savefig('test_tuple_mixed.png', bbox_inches = 'tight', pad_inches = [0, 2, -0.2, 4])

test_float_0
test_float_1
test_tuple_0
test_tuple_1
test_tuple_mixed

PR checklist

Added a new padding function to transforms.py, called it in backend_bases, and updated documentation where pad_inches shows up
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 week or so, please leave a new comment below and that should bring it to our attention. 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.

@ttshaw1
Copy link
Author

I have
[?] Documentation complies withgeneral anddocstring guidelines
as a question mark because I made an effort but I'm not positive I didn't overlook a convention.

Also, I didn't do much error checking. The logic is

                        if isinstance(pad_inches, (int, float)):                            l_pad = r_pad = b_pad = t_pad = pad_inches                        elif pad_inches in [None, "layout"]:                            pad_inches = rcParams['savefig.pad_inches']                            l_pad = r_pad = b_pad = t_pad = pad_inches                        else:                            l_pad = pad_inches[0]                            r_pad = pad_inches[1]                            b_pad = pad_inches[2]                            t_pad = pad_inches[3]

so if someone puts in a 3-tuple or some other weird datatype it's just going to return some default python error. Up to y'all what the best way to cover that sort of thing is.

@ttshaw1ttshaw1 marked this pull request as ready for reviewJune 17, 2025 18:13
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

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@ttshaw1

[8]ページ先頭

©2009-2025 Movatter.jp