diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 3d75e25bbf09..64f1e0eb8c11 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -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. @@ -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 diff --git a/lib/matplotlib/tests/test_backend_svg.py b/lib/matplotlib/tests/test_backend_svg.py index 1000cf02295d..d871affa8b16 100644 --- a/lib/matplotlib/tests/test_backend_svg.py +++ b/lib/matplotlib/tests/test_backend_svg.py @@ -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")