Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ac76de

Browse files
authored
Merge pull request #16989 from meeseeksmachine/auto-backport-of-pr-16980-on-v3.2.x
Backport PR #16980 on branch v3.2.x (Correctly disable more drawing methods in tight_bboxing renderer.)
2 parents 39e5589 + c341652 commit 8ac76de

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ def _get_renderer(figure, print_method, *, draw_disabled=False):
15211521
Get the renderer that would be used to save a `~.Figure`, and cache it on
15221522
the figure.
15231523
1524-
If *draw_disabled* is True, additionally replace draw_foo methods on
1524+
If *draw_disabled* is True, additionally replace drawing methods on
15251525
*renderer* by no-ops. This is used by the tight-bbox-saving renderer,
15261526
which needs to walk through the artist tree to compute the tight-bbox, but
15271527
for which the output file may be closed early.
@@ -1542,7 +1542,8 @@ def _draw(renderer): raise Done(renderer)
15421542

15431543
if draw_disabled:
15441544
for meth_name in dir(RendererBase):
1545-
if meth_name.startswith("draw_"):
1545+
if (meth_name.startswith("draw_")
1546+
or meth_name in ["open_group", "close_group"]):
15461547
setattr(renderer, meth_name, lambda *args, **kwargs: None)
15471548

15481549
return renderer

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,9 @@ def include(gid, obj):
205205
for gid, obj in gdic.items():
206206
if include(gid, obj):
207207
assert gid in buf
208+
209+
210+
def test_savefig_tight():
211+
# Check that the draw-disabled renderer correctly disables open/close_group
212+
# as well.
213+
plt.savefig(BytesIO(), format="svgz", bbox_inches="tight")

0 commit comments

Comments
 (0)