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

Skip to content

Commit f620c0e

Browse files
authored
Merge pull request #14134 from anntzer/dryrun
Deprecate the dryrun parameter to print_foo().
2 parents 4c70e91 + 71db23e commit f620c0e

File tree

6 files changed

+35
-13
lines changed

6 files changed

+35
-13
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Deprecations
2+
````````````
3+
4+
The ``dryrun`` parameter to the various ``FigureCanvasFoo.print_foo`` methods is deprecated.

lib/matplotlib/backend_bases.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,27 @@ def __init__(self, name, canvas, key, x=0, y=0, guiEvent=None):
15281528
self.key = key
15291529

15301530

1531+
def _get_renderer(figure, print_method):
1532+
"""
1533+
Get the renderer that would be used to save a `~.Figure`, and cache it on
1534+
the figure.
1535+
"""
1536+
# This is implemented by triggering a draw, then immediately jumping out of
1537+
# Figure.draw() by raising an exception.
1538+
1539+
class Done(Exception):
1540+
pass
1541+
1542+
def _draw(renderer): raise Done(renderer)
1543+
1544+
with cbook._setattr_cm(figure, draw=_draw):
1545+
try:
1546+
print_method(io.BytesIO())
1547+
except Done as exc:
1548+
figure._cachedRenderer, = exc.args
1549+
return figure._cachedRenderer
1550+
1551+
15311552
class FigureCanvasBase(object):
15321553
"""
15331554
The canvas the figure renders into.
@@ -2038,20 +2059,11 @@ def print_figure(self, filename, dpi=None, facecolor=None, edgecolor=None,
20382059
bbox_inches = rcParams['savefig.bbox']
20392060

20402061
if bbox_inches:
2041-
# call adjust_bbox to save only the given area
20422062
if bbox_inches == "tight":
2043-
# When bbox_inches == "tight", it saves the figure twice.
2044-
# The first save command (to a BytesIO) is just to estimate
2045-
# the bounding box of the figure.
2046-
result = print_method(
2047-
io.BytesIO(),
2048-
dpi=dpi,
2049-
facecolor=facecolor,
2050-
edgecolor=edgecolor,
2051-
orientation=orientation,
2052-
dryrun=True,
2053-
**kwargs)
2054-
renderer = self.figure._cachedRenderer
2063+
renderer = _get_renderer(
2064+
self.figure,
2065+
functools.partial(
2066+
print_method, dpi=dpi, orientation=orientation))
20552067
bbox_artists = kwargs.pop("bbox_extra_artists", None)
20562068
bbox_inches = self.figure.get_tightbbox(renderer,
20572069
bbox_extra_artists=bbox_artists)
@@ -2061,6 +2073,7 @@ def print_figure(self, filename, dpi=None, facecolor=None, edgecolor=None,
20612073

20622074
bbox_inches = bbox_inches.padded(pad)
20632075

2076+
# call adjust_bbox to save only the given area
20642077
restore_bbox = tight_bbox.adjust_bbox(self.figure, bbox_inches,
20652078
canvas.fixed_dpi)
20662079

lib/matplotlib/backends/backend_agg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ def print_to_buffer(self):
544544
# print_figure(), and the latter ensures that `self.figure.dpi` already
545545
# matches the dpi kwarg (if any).
546546

547+
@cbook._delete_parameter("3.2", "dryrun")
547548
def print_jpg(self, filename_or_obj, *args, dryrun=False,
548549
pil_kwargs=None, **kwargs):
549550
"""
@@ -598,6 +599,7 @@ def print_jpg(self, filename_or_obj, *args, dryrun=False,
598599

599600
print_jpeg = print_jpg
600601

602+
@cbook._delete_parameter("3.2", "dryrun")
601603
def print_tif(self, filename_or_obj, *args, dryrun=False,
602604
pil_kwargs=None, **kwargs):
603605
buf, size = self.print_to_buffer()

lib/matplotlib/backends/backend_pgf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ class FigureCanvasPgf(FigureCanvasBase):
775775
def get_default_filetype(self):
776776
return 'pdf'
777777

778+
@cbook._delete_parameter("3.2", "dryrun")
778779
def _print_pgf_to_fh(self, fh, *args,
779780
dryrun=False, bbox_inches_restore=None, **kwargs):
780781
if dryrun:

lib/matplotlib/backends/backend_ps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ def _print_ps(self, outfile, format, *args,
870870
orientation, isLandscape, papertype,
871871
**kwargs)
872872

873+
@cbook._delete_parameter("3.2", "dryrun")
873874
def _print_figure(
874875
self, outfile, format, dpi=72, facecolor='w', edgecolor='w',
875876
orientation='portrait', isLandscape=False, papertype=None,

lib/matplotlib/table.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ def get_children(self):
459459

460460
def get_window_extent(self, renderer):
461461
"""Return the bounding box of the table in window coords."""
462+
self._update_positions(renderer)
462463
boxes = [cell.get_window_extent(renderer)
463464
for cell in self._cells.values()]
464465
return Bbox.union(boxes)

0 commit comments

Comments
 (0)