Skip to content

Commit 42e933c

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 3c67db3 commit 42e933c

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
@@ -67,3 +67,9 @@ This attribute is unused and deprecated.
6767
``widgets.TextBox.params_to_disable``
6868
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6969
This attribute is deprecated.
70+
71+
PGF backend cleanups
72+
~~~~~~~~~~~~~~~~~~~~
73+
The *dummy* parameter of `.RendererPgf` is deprecated.
74+
75+
`.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
@@ -384,6 +384,7 @@ def _get_image_inclusion_command():
384384

385385
class RendererPgf(RendererBase):
386386

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

421415
@cbook.deprecated("3.2")
422416
def latexManager(self):
@@ -643,6 +637,11 @@ def draw_image(self, gc, x, y, im, transform=None):
643637
if w == 0 or h == 0:
644638
return
645639

640+
if not os.path.exists(getattr(self.fh, "name", "")):
641+
cbook._warn_external(
642+
"streamed pgf-code does not support raster graphics, consider "
643+
"using the pgf-to-pdf option.")
644+
646645
# save the images to png files
647646
path = pathlib.Path(self.fh.name)
648647
fname_img = "%s-img%d.png" % (path.stem, self.image_counter)
@@ -753,16 +752,11 @@ def points_to_pixels(self, points):
753752
# docstring inherited
754753
return points * mpl_pt_to_in * self.dpi
755754

756-
def new_gc(self):
757-
# docstring inherited
758-
return GraphicsContextPgf()
759-
760755

756+
@cbook.deprecated("3.3", alternative="GraphicsContextBase")
761757
class GraphicsContextPgf(GraphicsContextBase):
762758
pass
763759

764-
########################################################################
765-
766760

767761
class TmpDirCleaner:
768762
remaining_tmpdirs = set()
@@ -946,7 +940,7 @@ def print_png(self, fname_or_fh, *args, **kwargs):
946940
self._print_png_to_fh(file, *args, **kwargs)
947941

948942
def get_renderer(self):
949-
return RendererPgf(self.figure, None, dummy=True)
943+
return RendererPgf(self.figure, None)
950944

951945

952946
class FigureManagerPgf(FigureManagerBase):

0 commit comments

Comments
 (0)