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

Skip to content

Commit d4573c6

Browse files
authored
Merge pull request #26242 from anntzer/sb
Deprecate FigureCanvasBase.switch_backends.
2 parents d2fc3a4 + 8fdc2ad commit d4573c6

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``FigureCanvasBase.switch_backends``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... is deprecated with no replacement.

lib/matplotlib/backend_bases.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,19 +2013,19 @@ def _switch_canvas_and_return_print_method(self, fmt, backend=None):
20132013
if not hasattr(canvas_class, f"print_{fmt}"):
20142014
raise ValueError(
20152015
f"The {backend!r} backend does not support {fmt} output")
2016+
canvas = canvas_class(self.figure)
20162017
elif hasattr(self, f"print_{fmt}"):
20172018
# Return the current canvas if it supports the requested format.
20182019
canvas = self
2019-
canvas_class = None # Skip call to switch_backends.
20202020
else:
20212021
# Return a default canvas for the requested format, if it exists.
20222022
canvas_class = get_registered_canvas_class(fmt)
2023-
if canvas_class:
2024-
canvas = self.switch_backends(canvas_class)
2025-
if canvas is None:
2026-
raise ValueError(
2027-
"Format {!r} is not supported (supported formats: {})".format(
2028-
fmt, ", ".join(sorted(self.get_supported_filetypes()))))
2023+
if canvas_class is None:
2024+
raise ValueError(
2025+
"Format {!r} is not supported (supported formats: {})".format(
2026+
fmt, ", ".join(sorted(self.get_supported_filetypes()))))
2027+
canvas = canvas_class(self.figure)
2028+
canvas._is_saving = self._is_saving
20292029
meth = getattr(canvas, f"print_{fmt}")
20302030
mod = (meth.func.__module__
20312031
if hasattr(meth, "func") # partialmethod, e.g. backend_wx.
@@ -2214,6 +2214,7 @@ def get_default_filename(self):
22142214
filename = basename + '.' + filetype
22152215
return filename
22162216

2217+
@_api.deprecated("3.8")
22172218
def switch_backends(self, FigureCanvasClass):
22182219
"""
22192220
Instantiate an instance of FigureCanvasClass

0 commit comments

Comments
 (0)