Skip to content

Commit 02b379c

Browse files
committed
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).
1 parent b42d6d9 commit 02b379c

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,9 @@ an internal helper).
338338
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
339339
This method is deprecated. If needed, directly assign to the ``params``
340340
attribute of the Substitution object.
341+
342+
PGF backend cleanups
343+
~~~~~~~~~~~~~~~~~~~~
344+
The *dummy* parameter of `.RendererPgf` is deprecated.
345+
346+
`.GraphicsContextPgf` is deprecated (use `.GraphicsContextBase` instead).

lib/matplotlib/backends/backend_pgf.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ def _get_image_inclusion_command():
386386

387387
class RendererPgf(RendererBase):
388388

389+
@cbook._delete_parameter("3.3", "dummy")
389390
def __init__(self, figure, fh, dummy=False):
390391
"""
391392
Creates a new PGF renderer that translates any drawing instruction
@@ -412,13 +413,6 @@ def __init__(self, figure, fh, dummy=False):
412413
for m in RendererPgf.__dict__:
413414
if m.startswith("draw_"):
414415
self.__dict__[m] = lambda *args, **kwargs: None
415-
else:
416-
# if fh does not belong to a filename, deactivate draw_image
417-
if not hasattr(fh, 'name') or not os.path.exists(fh.name):
418-
self.__dict__["draw_image"] = \
419-
lambda *args, **kwargs: cbook._warn_external(
420-
"streamed pgf-code does not support raster graphics, "
421-
"consider using the pgf-to-pdf option")
422416

423417
@cbook.deprecated("3.2")
424418
@property
@@ -646,6 +640,11 @@ def draw_image(self, gc, x, y, im, transform=None):
646640
if w == 0 or h == 0:
647641
return
648642

643+
if not os.path.exists(getattr(self.fh, "name", "")):
644+
cbook._warn_external(
645+
"streamed pgf-code does not support raster graphics, consider "
646+
"using the pgf-to-pdf option.")
647+
649648
# save the images to png files
650649
path = pathlib.Path(self.fh.name)
651650
fname_img = "%s-img%d.png" % (path.stem, self.image_counter)
@@ -756,16 +755,11 @@ def points_to_pixels(self, points):
756755
# docstring inherited
757756
return points * mpl_pt_to_in * self.dpi
758757

759-
def new_gc(self):
760-
# docstring inherited
761-
return GraphicsContextPgf()
762-
763758

759+
@cbook.deprecated("3.3", alternative="GraphicsContextBase")
764760
class GraphicsContextPgf(GraphicsContextBase):
765761
pass
766762

767-
########################################################################
768-
769763

770764
class TmpDirCleaner:
771765
remaining_tmpdirs = set()
@@ -949,7 +943,7 @@ def print_png(self, fname_or_fh, *args, **kwargs):
949943
self._print_png_to_fh(file, *args, **kwargs)
950944

951945
def get_renderer(self):
952-
return RendererPgf(self.figure, None, dummy=True)
946+
return RendererPgf(self.figure, None)
953947

954948

955949
class FigureManagerPgf(FigureManagerBase):

0 commit comments

Comments
 (0)