Skip to content

pgf: draw_image() doesn't store path to png files in the pgf source #1509

@thecom

Description

@thecom

If a figure with an image is to be saved as 'path/file.pgf', the png file of the image is written into path. However the \pgfimage command in the pgf file omits the path. The following patch fixes this problem for me (not tested in any other way):

--- a/lib/matplotlib/backends/backend_pgf.py
+++ b/lib/matplotlib/backends/backend_pgf.py
@@ -581,11 +581,12 @@ class RendererPgf(RendererBase):
         # save the images to png files
         path = os.path.dirname(self.fh.name)
         fname = os.path.splitext(os.path.basename(self.fh.name))[0]
-        fname_img = "%s-img%d.png" % (fname, self.image_counter)
+        fname_img = os.path.join(path,
+                "%s-img%d.png" % (fname, self.image_counter))
         self.image_counter += 1
         im.flipud_out()
         rows, cols, buf = im.as_rgba_str()
-        _png.write_png(buf, cols, rows, os.path.join(path, fname_img))
+        _png.write_png(buf, cols, rows, fname_img)

         # reference the image in the pgf picture
         writeln(self.fh, r"\begin{pgfscope}")

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions