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

Closed
opened this Issue Nov 16, 2012 · 3 comments

Projects
None yet
2 participants

### thecom commented Nov 16, 2012

 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}")

Contributor

### pwuertz commented Nov 18, 2012

 Hey, sorry this took so long. I must have overlooked the notification. Omitting the path is the intended behaviour. Hardcoding the file path into the pgf file is error prone, for example when renaming the directory your files reside in or when saving the pgf to an absolute path. The inconvenience with LaTeX's include command is that it just copies the code from an included file into the main document, which puts any relative path information within that code out of context. This can be fixed by using the import package. I added this explanation, which is basically the same when saving to pdf+tex with inkscape, to the header of the pgf files: %% Figures using additional raster images can only be included by \input if %% they are in the same directory as the main LaTeX file. For loading figures %% from other directories you can use the import package %% \usepackage{import} %% and then include the figures with %% \import{path to file}{filename.pgf}
Contributor

### pwuertz commented Nov 18, 2012

 I believe this explains the problem you are having, hence closing the issue. Please feel free to re-open if this is incorrect.

### thecom commented Nov 29, 2012

 No, this is perfectly fine. I didn't know about the import package and that seems to be a better solution. Thanks a lot :)
to join this conversation on GitHub. Already have an account? Sign in to comment