Skip to content

Commit c30129b

Browse files
authored
Merge pull request #16980 from anntzer/draw_disabled
Correctly disable more drawing methods in tight_bboxing renderer.
2 parents 98560a8 + 001afaf commit c30129b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/matplotlib/backend_bases.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ def _get_renderer(figure, print_method, *, draw_disabled=False):
15001500
Get the renderer that would be used to save a `~.Figure`, and cache it on
15011501
the figure.
15021502
1503-
If *draw_disabled* is True, additionally replace draw_foo methods on
1503+
If *draw_disabled* is True, additionally replace drawing methods on
15041504
*renderer* by no-ops. This is used by the tight-bbox-saving renderer,
15051505
which needs to walk through the artist tree to compute the tight-bbox, but
15061506
for which the output file may be closed early.
@@ -1521,7 +1521,8 @@ def _draw(renderer): raise Done(renderer)
15211521

15221522
if draw_disabled:
15231523
for meth_name in dir(RendererBase):
1524-
if meth_name.startswith("draw_"):
1524+
if (meth_name.startswith("draw_")
1525+
or meth_name in ["open_group", "close_group"]):
15251526
setattr(renderer, meth_name, lambda *args, **kwargs: None)
15261527

15271528
return renderer

lib/matplotlib/tests/test_backend_svg.py

+6
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,9 @@ def include(gid, obj):
207207
for gid, obj in gdic.items():
208208
if include(gid, obj):
209209
assert gid in buf
210+
211+
212+
def test_savefig_tight():
213+
# Check that the draw-disabled renderer correctly disables open/close_group
214+
# as well.
215+
plt.savefig(BytesIO(), format="svgz", bbox_inches="tight")

0 commit comments

Comments
 (0)