Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
[FIX]: Make inset axes transparent on savefig(..., transparent=True)#24816
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
lib/matplotlib/tests/test_figure.py Outdated
@image_comparison(['transparent_background'], | ||
extensions=['png'], savefig_kwarg={'transparent': True}, | ||
remove_text=True) | ||
def test_savefig_transparent(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@anntzer one reason I did not implement the complete empty plot test mentioned in the previous PR was that that test would pass even if there is nothing being done while plotting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yes, but it's extremely unlikely that we'd ever introduce a bug such thatax.spines[:].set_visible(False); ax.set(xticks=[], yticks=[])
would actually disable all drawing.
If you want to feel extra safe I would still do a check_figures_equal where the reference figure has all axesmanually made transparent with set_facecolor("none") calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ah okay. Yeah, I'll do that then. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I had a quick question. Since this is related to a savefig parameter, I'll need to pass that to the savefig function inside the decorator. From what I can see, that's not possible right now withcheck_figures_equal
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@anntzer any suggestions on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Something like
@mpl.rc_context({"savefig.transparent":True})@check_figures_equal(extensions=["png"])deftest_savefig_transparent(fig_test,fig_ref):# create two transparent subfigures with corresponding transparent inset# axes. the entire background of the image should be transparent.gs1=fig_test.add_gridspec(3,3,left=0.05,wspace=0.05)f1=fig_test.add_subfigure(gs1[:, :])f2=f1.add_subfigure(gs1[0,0])ax12=f2.add_subplot(gs1[:, :])ax1=f1.add_subplot(gs1[:-1, :])iax1=ax1.inset_axes([.1,.2,.3,.4])iax2=iax1.inset_axes([.1,.2,.3,.4])ax2=fig_test.add_subplot(gs1[-1, :-1])ax3=fig_test.add_subplot(gs1[-1,-1])foraxin [ax12,ax1,iax1,iax2,ax2,ax3]:ax.set(xticks=[],yticks=[])ax.spines[:].set_visible(False)# and draw nothing on fig_ref.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Did not know aboutmpl.rc_context
. This should work, thanks!
chahak13 commentedDec 26, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
PR cleanliness check is failing because of the test file being changed. I can squash all of it and force push but will that remove the original author's commit info since there's only one commit? I don't want to do that ideally. |
@chahak13 you could add the original author as a co-author in the single commit: |
1b2153c
toc59a7fa
Compare4d95dc9
tob807359
CompareThis appears to need a rebase to get the docs build working. |
Co-authored-by: Shreeya Ramesh <shreeyar@umich.edu>Co-authored-by: Chahak Mehta <chahakmehta013@gmail.com>
b807359
to0b3348a
CompareConflict was caused by the new test being right above the test frommatplotlib#24816, which is not in the v3.7.x branch.FIX: use locators in adjust_bbox(cherry picked from commit8ef978d)
PR Summary
This is a continuation on#22816 to make sure
savefig(..., transparent=True)
handles nested figures and axes. Also updates the test figure to include doubly-nested cases to test against.Closes issue#22674
PR Checklist
Documentation and Tests
pytest
passes)Release Notes
.. versionadded::
directive in the docstring and documented indoc/users/next_whats_new/
.. versionchanged::
directive in the docstring and documented indoc/api/next_api_changes/
next_whats_new/README.rst
ornext_api_changes/README.rst