From 02b379ca18cfe0712126605e94cabaa674d7005c Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 19 Dec 2019 11:02:28 +0100 Subject: [PATCH] pgf backend cleanups. Deprecate dummy renderers (which are only used with dryrun=True, which is itself deprecated). Move the image-to-stream warning to draw_image. Deprecate GraphicsContextPgf (we can just use GraphicsContextBase directly; e.g. the Agg backend does the same). --- doc/api/next_api_changes/deprecations.rst | 6 ++++++ lib/matplotlib/backends/backend_pgf.py | 22 ++++++++-------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/doc/api/next_api_changes/deprecations.rst b/doc/api/next_api_changes/deprecations.rst index 34d052f9bedc..55a7b1f41dfd 100644 --- a/doc/api/next_api_changes/deprecations.rst +++ b/doc/api/next_api_changes/deprecations.rst @@ -338,3 +338,9 @@ an internal helper). ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This method is deprecated. If needed, directly assign to the ``params`` attribute of the Substitution object. + +PGF backend cleanups +~~~~~~~~~~~~~~~~~~~~ +The *dummy* parameter of `.RendererPgf` is deprecated. + +`.GraphicsContextPgf` is deprecated (use `.GraphicsContextBase` instead). diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index da124a2dde69..c7469ee9f329 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -386,6 +386,7 @@ def _get_image_inclusion_command(): class RendererPgf(RendererBase): + @cbook._delete_parameter("3.3", "dummy") def __init__(self, figure, fh, dummy=False): """ Creates a new PGF renderer that translates any drawing instruction @@ -412,13 +413,6 @@ def __init__(self, figure, fh, dummy=False): for m in RendererPgf.__dict__: if m.startswith("draw_"): self.__dict__[m] = lambda *args, **kwargs: None - else: - # if fh does not belong to a filename, deactivate draw_image - if not hasattr(fh, 'name') or not os.path.exists(fh.name): - self.__dict__["draw_image"] = \ - lambda *args, **kwargs: cbook._warn_external( - "streamed pgf-code does not support raster graphics, " - "consider using the pgf-to-pdf option") @cbook.deprecated("3.2") @property @@ -646,6 +640,11 @@ def draw_image(self, gc, x, y, im, transform=None): if w == 0 or h == 0: return + if not os.path.exists(getattr(self.fh, "name", "")): + cbook._warn_external( + "streamed pgf-code does not support raster graphics, consider " + "using the pgf-to-pdf option.") + # save the images to png files path = pathlib.Path(self.fh.name) fname_img = "%s-img%d.png" % (path.stem, self.image_counter) @@ -756,16 +755,11 @@ def points_to_pixels(self, points): # docstring inherited return points * mpl_pt_to_in * self.dpi - def new_gc(self): - # docstring inherited - return GraphicsContextPgf() - +@cbook.deprecated("3.3", alternative="GraphicsContextBase") class GraphicsContextPgf(GraphicsContextBase): pass -######################################################################## - class TmpDirCleaner: remaining_tmpdirs = set() @@ -949,7 +943,7 @@ def print_png(self, fname_or_fh, *args, **kwargs): self._print_png_to_fh(file, *args, **kwargs) def get_renderer(self): - return RendererPgf(self.figure, None, dummy=True) + return RendererPgf(self.figure, None) class FigureManagerPgf(FigureManagerBase):