Skip to content

Commit

Permalink
Merge pull request #22516 from oscargus/backenddeprecations
Browse files Browse the repository at this point in the history
Expire deprecations in backends
  • Loading branch information
timhoffm committed Mar 6, 2022
2 parents ed5c0b3 + e1eca0a commit 7b2d828
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 76 deletions.
20 changes: 20 additions & 0 deletions doc/api/next_api_changes/removals/22516-OG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Removal of deprecations in ``backends``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The parameter ``resize_callback`` is removed from the Tk backend. Instead,
use ``get_tk_widget().bind('<Configure>', ..., True)``.

The ``get_content_extents()`` and ``tostring_rgba_minimized()`` methods are
removed from the Agg backend with no replacements.

The parameter ``dpi`` is removed from ``print_ps()`` in the PS backend and
``print_pdf()`` in the PDF backend. Instead, the methods obtain the DPI from
the ``savefig`` machinery.

The classes ``TmpDirCleaner`` and ``GraphicsContextPS`` are removed from the
PGF and PS backends, respectively. For the latter, ``GraphicsContextBase`` can
be used as a replacement.

In the WX backend, the property ``IDLE_DELAY`` is removed. In addition, the
parameter ``origin`` of ``gui_repaint()`` is removed, as well as the method
``get_canvas()``. No replacements are provided.
8 changes: 1 addition & 7 deletions lib/matplotlib/backends/_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,7 @@ def _on_timer(self):
class FigureCanvasTk(FigureCanvasBase):
required_interactive_framework = "tk"

@_api.delete_parameter(
"3.4", "resize_callback",
alternative="get_tk_widget().bind('<Configure>', ..., True)")
def __init__(self, figure=None, master=None, resize_callback=None):
def __init__(self, figure=None, master=None):
super().__init__(figure)
self._idle_draw_id = None
self._event_loop_id = None
Expand All @@ -177,7 +174,6 @@ def __init__(self, figure=None, master=None, resize_callback=None):
self._tkphoto = tk.PhotoImage(
master=self._tkcanvas, width=w, height=h)
self._tkcanvas.create_image(w//2, h//2, image=self._tkphoto)
self._resize_callback = resize_callback
self._tkcanvas.bind("<Configure>", self.resize)
self._tkcanvas.bind("<Map>", self._update_device_pixel_ratio)
self._tkcanvas.bind("<Key>", self.key_press)
Expand Down Expand Up @@ -229,8 +225,6 @@ def _update_device_pixel_ratio(self, event=None):

def resize(self, event):
width, height = event.width, event.height
if self._resize_callback is not None:
self._resize_callback(event)

# compute desired figure size in inches
dpival = self.figure.dpi
Expand Down
15 changes: 0 additions & 15 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,6 @@ def _update_methods(self):
self.draw_quad_mesh = self._renderer.draw_quad_mesh
self.copy_from_bbox = self._renderer.copy_from_bbox

@_api.deprecated("3.4")
def get_content_extents(self):
orig_img = np.asarray(self.buffer_rgba())
slice_y, slice_x = cbook._get_nonzero_slices(orig_img[..., 3])
return (slice_x.start, slice_y.start,
slice_x.stop - slice_x.start, slice_y.stop - slice_y.start)

@_api.deprecated("3.4")
def tostring_rgba_minimized(self):
extents = self.get_content_extents()
bbox = [[extents[0], self.height - (extents[1] + extents[3])],
[extents[0] + extents[2], self.height - extents[1]]]
region = self.copy_from_bbox(bbox)
return np.array(region), extents

def draw_path(self, gc, path, transform, rgbFace=None):
# docstring inherited
nmax = mpl.rcParams['agg.path.chunksize'] # here at least for testing
Expand Down
5 changes: 1 addition & 4 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2738,13 +2738,10 @@ class FigureCanvasPdf(FigureCanvasBase):
def get_default_filetype(self):
return 'pdf'

@_api.delete_parameter("3.4", "dpi")
def print_pdf(self, filename, *,
dpi=None, # dpi to use for images
bbox_inches_restore=None, metadata=None):

if dpi is None: # always use this branch after deprecation elapses.
dpi = self.figure.get_dpi()
dpi = self.figure.get_dpi()
self.figure.set_dpi(72) # there are 72 pdf points to an inch
width, height = self.figure.get_size_inches()
if isinstance(filename, PdfPages):
Expand Down
25 changes: 0 additions & 25 deletions lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,31 +771,6 @@ def points_to_pixels(self, points):
return points * mpl_pt_to_in * self.dpi


@_api.deprecated("3.4")
class TmpDirCleaner:
_remaining_tmpdirs = set()

@_api.classproperty
@_api.deprecated("3.4")
def remaining_tmpdirs(cls):
return cls._remaining_tmpdirs

@staticmethod
@_api.deprecated("3.4")
def add(tmpdir):
TmpDirCleaner._remaining_tmpdirs.add(tmpdir)

@staticmethod
@_api.deprecated("3.4")
@atexit.register
def cleanup_remaining_tmpdirs():
for tmpdir in TmpDirCleaner._remaining_tmpdirs:
error_message = "error deleting tmp directory {}".format(tmpdir)
shutil.rmtree(
tmpdir,
onerror=lambda *args: _log.error(error_message))


class FigureCanvasPgf(FigureCanvasBase):
filetypes = {"pgf": "LaTeX PGF picture",
"pdf": "LaTeX compiled PGF picture",
Expand Down
15 changes: 2 additions & 13 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,15 +806,6 @@ def _draw_ps(self, ps, gc, rgbFace, *, fill=True, stroke=True):
write("grestore\n")


@_api.deprecated("3.4", alternative="GraphicsContextBase")
class GraphicsContextPS(GraphicsContextBase):
def get_capstyle(self):
return {'butt': 0, 'round': 1, 'projecting': 2}[super().get_capstyle()]

def get_joinstyle(self):
return {'miter': 0, 'round': 1, 'bevel': 2}[super().get_joinstyle()]


class _Orientation(Enum):
portrait, landscape = range(2)

Expand All @@ -830,15 +821,13 @@ class FigureCanvasPS(FigureCanvasBase):
def get_default_filetype(self):
return 'ps'

@_api.delete_parameter("3.4", "dpi")
@_api.delete_parameter("3.5", "args")
def _print_ps(
self, fmt, outfile, *args,
dpi=None, metadata=None, papertype=None, orientation='portrait',
metadata=None, papertype=None, orientation='portrait',
**kwargs):

if dpi is None: # always use this branch after deprecation elapses.
dpi = self.figure.get_dpi()
dpi = self.figure.get_dpi()
self.figure.set_dpi(72) # Override the dpi kwarg

dsc_comments = {}
Expand Down
6 changes: 2 additions & 4 deletions lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1281,9 +1281,8 @@ class FigureCanvasSVG(FigureCanvasBase):

fixed_dpi = 72

@_api.delete_parameter("3.4", "dpi")
@_api.delete_parameter("3.5", "args")
def print_svg(self, filename, *args, dpi=None, bbox_inches_restore=None,
def print_svg(self, filename, *args, bbox_inches_restore=None,
metadata=None):
"""
Parameters
Expand Down Expand Up @@ -1319,8 +1318,7 @@ def print_svg(self, filename, *args, dpi=None, bbox_inches_restore=None,
with cbook.open_file_cm(filename, "w", encoding="utf-8") as fh:
if not cbook.file_requires_unicode(fh):
fh = codecs.getwriter('utf-8')(fh)
if dpi is None: # always use this branch after deprecation elapses
dpi = self.figure.get_dpi()
dpi = self.figure.get_dpi()
self.figure.set_dpi(72)
width, height = self.figure.get_size_inches()
w, h = width * 72, height * 72
Expand Down
9 changes: 1 addition & 8 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@

@_api.caching_module_getattr # module-level deprecations
class __getattr__:
IDLE_DELAY = _api.deprecated("3.1", obj_type="", removal="3.6")(property(
lambda self: 5))
cursord = _api.deprecated("3.5", obj_type="")(property(lambda self: {
cursors.MOVE: wx.CURSOR_HAND,
cursors.HAND: wx.CURSOR_HAND,
Expand Down Expand Up @@ -593,8 +591,7 @@ def _get_imagesave_wildcards(self):
wildcards = '|'.join(wildcards)
return wildcards, extensions, filter_index

@_api.delete_parameter("3.4", "origin")
def gui_repaint(self, drawDC=None, origin='WX'):
def gui_repaint(self, drawDC=None):
"""
Update the displayed image on the GUI canvas, using the supplied
wx.PaintDC device context.
Expand Down Expand Up @@ -1084,10 +1081,6 @@ def _icon(name):
return wx.Bitmap.FromBufferRGBA(
image.shape[1], image.shape[0], image.tobytes())

@_api.deprecated("3.4")
def get_canvas(self, frame, fig):
return type(self.canvas)(frame, -1, fig)

def _update_buttons_checked(self):
if "Pan" in self.wx_ids:
self.ToggleTool(self.wx_ids["Pan"], self.mode.name == "PAN")
Expand Down

0 comments on commit 7b2d828

Please sign in to comment.