# Insert pgf with referenced png file from a different folder

I'm trying to insert a pgf file that I made with matplotlib. This file references to a png file (since I inserted a png figure in the plot).

When I put the png in the same folder than my tex file, everything works, but if the png file is in the folder with the pgf file, i got an error

Package pgf Warning: File "plot2.png" not found when def
ining image "pgflastimage".


I was trying to use import but I don't know how it works for a pgf. If I change pgf by tex, it still doesn't find the png:

\documentclass{article}
\usepackage{pgf}
\usepackage{import}

\begin{document}

% \subimport{../pgf/}{plot.pgf} --> Not working
\input{../pgf/plot.pgf}

\end{document}


EDIT:

Changing \pgfimage{...} by \includegraphics{...} in the pgf file, seems to work with subimport* . However, matplotlib produces the pgf with pgfimage, so it would be necessary to change the output plots by hand. Maybe someone knows a better solution.

• Where? In the pgf file? =o – PerroNoob Jul 29 '14 at 22:22
• Same problem here. I didn't find a proper answer yet.. – user62681 Sep 17 '14 at 16:21

From what I found, there is no better way. This answer notes that pgfimage uses includegraphics, but does not propagate the relative paths. Looking through the matplotlib pgf backend source, changing pgfimage to includegraphics does not appear to be a configurable option on the matplotlib side of the equation.

A work around I came up with was to intercept the output and update the appropriate lines.

# lots of plotting commands
fig.savefig(output)
_, ext = os.path.splitext(output)
if ext == ".pgf":
with open(output, "r") as fid: