diff --git a/doc/api/next_api_changes/deprecations/19487-AL.rst b/doc/api/next_api_changes/deprecations/19487-AL.rst new file mode 100644 index 000000000000..6466e0516994 --- /dev/null +++ b/doc/api/next_api_changes/deprecations/19487-AL.rst @@ -0,0 +1,6 @@ +Unused positional parameters to ``print_`` methods are deprecated +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +None of the ``print_`` methods implemented by canvas subclasses used +positional arguments other that the first (the output filename or file-like), +so these extra parameters are deprecated. diff --git a/lib/matplotlib/backends/backend_agg.py b/lib/matplotlib/backends/backend_agg.py index a9b0383f4bdd..1e48fd0d7725 100644 --- a/lib/matplotlib/backends/backend_agg.py +++ b/lib/matplotlib/backends/backend_agg.py @@ -448,6 +448,7 @@ def buffer_rgba(self): return self.renderer.buffer_rgba() @_check_savefig_extra_args + @_api.delete_parameter("3.5", "args") def print_raw(self, filename_or_obj, *args): FigureCanvasAgg.draw(self) renderer = self.get_renderer() @@ -457,6 +458,7 @@ def print_raw(self, filename_or_obj, *args): print_rgba = print_raw @_check_savefig_extra_args + @_api.delete_parameter("3.5", "args") def print_png(self, filename_or_obj, *args, metadata=None, pil_kwargs=None): """ @@ -528,6 +530,7 @@ def print_to_buffer(self): alternative="pil_kwargs={'optimize': ...}") @_api.delete_parameter("3.3", "progressive", alternative="pil_kwargs={'progressive': ...}") + @_api.delete_parameter("3.5", "args") def print_jpg(self, filename_or_obj, *args, pil_kwargs=None, **kwargs): """ Write the figure to a JPEG file. diff --git a/lib/matplotlib/backends/backend_gtk3agg.py b/lib/matplotlib/backends/backend_gtk3agg.py index ecd15327aa02..9c26e21753ae 100644 --- a/lib/matplotlib/backends/backend_gtk3agg.py +++ b/lib/matplotlib/backends/backend_gtk3agg.py @@ -70,11 +70,6 @@ def draw(self): backend_agg.FigureCanvasAgg.draw(self) super().draw() - def print_png(self, filename, *args, **kwargs): - # Do this so we can save the resolution of figure in the PNG file - agg = self.switch_backends(backend_agg.FigureCanvasAgg) - return agg.print_png(filename, *args, **kwargs) - class FigureManagerGTK3Agg(backend_gtk3.FigureManagerGTK3): pass diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index 9d01f603e021..a683d903edb7 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -843,7 +843,7 @@ def _print_pgf_to_fh(self, fh, *, bbox_inches_restore=None): writeln(fh, r"\makeatother") writeln(fh, r"\endgroup") - def print_pgf(self, fname_or_fh, *args, **kwargs): + def print_pgf(self, fname_or_fh, **kwargs): """ Output pgf macros for drawing the figure so it can be included and rendered in latex documents. @@ -851,9 +851,9 @@ def print_pgf(self, fname_or_fh, *args, **kwargs): with cbook.open_file_cm(fname_or_fh, "w", encoding="utf-8") as file: if not cbook.file_requires_unicode(file): file = codecs.getwriter("utf-8")(file) - self._print_pgf_to_fh(file, *args, **kwargs) + self._print_pgf_to_fh(file, **kwargs) - def print_pdf(self, fname_or_fh, *args, metadata=None, **kwargs): + def print_pdf(self, fname_or_fh, *, metadata=None, **kwargs): """Use LaTeX to compile a pgf generated figure to pdf.""" w, h = self.figure.get_figwidth(), self.figure.get_figheight() @@ -865,7 +865,7 @@ def print_pdf(self, fname_or_fh, *args, metadata=None, **kwargs): tmppath = pathlib.Path(tmpdir) # print figure to pgf and compile it with latex - self.print_pgf(tmppath / "figure.pgf", *args, **kwargs) + self.print_pgf(tmppath / "figure.pgf", **kwargs) latexcode = """ \\PassOptionsToPackage{pdfinfo={%s}}{hyperref} @@ -891,14 +891,14 @@ def print_pdf(self, fname_or_fh, *args, metadata=None, **kwargs): cbook.open_file_cm(fname_or_fh, "wb") as dest: shutil.copyfileobj(orig, dest) # copy file contents to target - def print_png(self, fname_or_fh, *args, **kwargs): + def print_png(self, fname_or_fh, **kwargs): """Use LaTeX to compile a pgf figure to pdf and convert it to png.""" converter = make_pdf_to_png_converter() with TemporaryDirectory() as tmpdir: tmppath = pathlib.Path(tmpdir) pdf_path = tmppath / "figure.pdf" png_path = tmppath / "figure.png" - self.print_pdf(pdf_path, *args, **kwargs) + self.print_pdf(pdf_path, **kwargs) converter(pdf_path, png_path, dpi=self.figure.dpi) with png_path.open("rb") as orig, \ cbook.open_file_cm(fname_or_fh, "wb") as dest: diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 5dbc841adc92..0e5e4823ca09 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -823,15 +823,17 @@ class FigureCanvasPS(FigureCanvasBase): def get_default_filetype(self): return 'ps' + @_api.delete_parameter("3.5", "args") def print_ps(self, outfile, *args, **kwargs): - return self._print_ps(outfile, 'ps', *args, **kwargs) + return self._print_ps(outfile, 'ps', **kwargs) + @_api.delete_parameter("3.5", "args") def print_eps(self, outfile, *args, **kwargs): - return self._print_ps(outfile, 'eps', *args, **kwargs) + return self._print_ps(outfile, 'eps', **kwargs) @_api.delete_parameter("3.4", "dpi") def _print_ps( - self, outfile, format, *args, + self, outfile, format, *, dpi=None, metadata=None, papertype=None, orientation='portrait', **kwargs): diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/backend_svg.py index 21a853693b1c..a997f4a85463 100644 --- a/lib/matplotlib/backends/backend_svg.py +++ b/lib/matplotlib/backends/backend_svg.py @@ -1286,6 +1286,7 @@ class FigureCanvasSVG(FigureCanvasBase): fixed_dpi = 72 + @_api.delete_parameter("3.5", "args") def print_svg(self, filename, *args, **kwargs): """ Parameters @@ -1337,6 +1338,7 @@ def print_svg(self, filename, *args, **kwargs): if detach: fh.detach() + @_api.delete_parameter("3.5", "args") def print_svgz(self, filename, *args, **kwargs): with cbook.open_file_cm(filename, "wb") as fh, \ gzip.GzipFile(mode='w', fileobj=fh) as gzipwriter: diff --git a/lib/matplotlib/backends/backend_template.py b/lib/matplotlib/backends/backend_template.py index 7ed017a0c6eb..62888efd67e6 100644 --- a/lib/matplotlib/backends/backend_template.py +++ b/lib/matplotlib/backends/backend_template.py @@ -29,6 +29,7 @@ plt.savefig("figure.xyz") """ +from matplotlib import _api from matplotlib._pylab_helpers import Gcf from matplotlib.backend_bases import ( FigureCanvasBase, FigureManagerBase, GraphicsContextBase, RendererBase) @@ -209,6 +210,7 @@ def draw(self): # you should add it to the class-scope filetypes dictionary as follows: filetypes = {**FigureCanvasBase.filetypes, 'foo': 'My magic Foo format'} + @_api.delete_parameter("3.5", "args") def print_foo(self, filename, *args, **kwargs): """ Write out format foo.