[FIX]: Make inset axes transparent on savefig(..., transparent=True)#24816
[FIX]: Make inset axes transparent on savefig(..., transparent=True)#24816ksunden merged 1 commit intomatplotlib:mainfrom
Conversation
| @image_comparison(['transparent_background'], | ||
| extensions=['png'], savefig_kwarg={'transparent': True}, | ||
| remove_text=True) | ||
| def test_savefig_transparent(): |
There was a problem hiding this comment.
@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.
Yes, but it's extremely unlikely that we'd ever introduce a bug such that ax.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 axes manually made transparent with set_facecolor("none") calls.
There was a problem hiding this comment.
Ah okay. Yeah, I'll do that then. Thanks.
There was a problem hiding this comment.
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 with check_figures_equal?
There was a problem hiding this comment.
Something like
@mpl.rc_context({"savefig.transparent": True})
@check_figures_equal(extensions=["png"])
def test_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])
for ax in [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.
Did not know about mpl.rc_context. This should work, thanks!
|
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 to
c59a7fa
Compare
4d95dc9 to
b807359
Compare
|
This 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 to
0b3348a
Compare
Conflict was caused by the new test being right above the test from matplotlib#24816, which is not in the v3.7.x branch. FIX: use locators in adjust_bbox (cherry picked from commit 8ef978d)
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
pytestpasses)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.rstornext_api_changes/README.rst