Skip to content

Correctly disable more drawing methods in tight_bboxing renderer. #16980

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
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ def _get_renderer(figure, print_method, *, draw_disabled=False):
Get the renderer that would be used to save a `~.Figure`, and cache it on
the figure.

If *draw_disabled* is True, additionally replace draw_foo methods on
If *draw_disabled* is True, additionally replace drawing methods on
*renderer* by no-ops. This is used by the tight-bbox-saving renderer,
which needs to walk through the artist tree to compute the tight-bbox, but
for which the output file may be closed early.
Expand All @@ -1521,7 +1521,8 @@ def _draw(renderer): raise Done(renderer)

if draw_disabled:
for meth_name in dir(RendererBase):
if meth_name.startswith("draw_"):
if (meth_name.startswith("draw_")
or meth_name in ["open_group", "close_group"]):
setattr(renderer, meth_name, lambda *args, **kwargs: None)

return renderer
Expand Down
6 changes: 6 additions & 0 deletions lib/matplotlib/tests/test_backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,9 @@ def include(gid, obj):
for gid, obj in gdic.items():
if include(gid, obj):
assert gid in buf


def test_savefig_tight():
# Check that the draw-disabled renderer correctly disables open/close_group
# as well.
plt.savefig(BytesIO(), format="svgz", bbox_inches="tight")