From 9ff89109e668d159cacf9f5e64b77fba207a2802 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 17 May 2021 19:30:01 +0200 Subject: [PATCH] Replace pgf image-streaming warning by error. Saving a pgf file with images to an in-memory buffer (`import io; imshow([[1, 2]]); savefig(io.BytesIO(), format="pgf")`) currently warns that this is not possible (because the image needs to be written to the filesyste), but in fact an exception gets raised immediately after when trying to construct `Path(self.fh.name)`, so we may as well replace the original warning by an exception. --- lib/matplotlib/backends/backend_pgf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index 1a647d37153f..fe964dd77fae 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -624,9 +624,9 @@ def draw_image(self, gc, x, y, im, transform=None): return if not os.path.exists(getattr(self.fh, "name", "")): - _api.warn_external( + raise ValueError( "streamed pgf-code does not support raster graphics, consider " - "using the pgf-to-pdf option.") + "using the pgf-to-pdf option") # save the images to png files path = pathlib.Path(self.fh.name)