I am using the tikz library external a lot and with success - so far. Now, I need to import an external file (eps, png, pdf... I don't care), and add the axes. I know I can do this with \addplot graphics, but it only works in documents without externalize. If I use this library, the figure remains empty or produces some weird stuff. Here's an MWE:

\tikzset{external/force remake=false}


\begin{axis}[axis on top,title=Test]
\addplot graphics[xmin=0,xmax=1,ymin=0,ymax=1]


If I remove the three lines concerning externalization, it works fine, but not like this.

Is there any way I can use both in the same document or do I have to get the axes around my surf plots by compiling them in a separate document?

Edit: Just found out that dropping the option prefix=pics/ works. I don't know why. Plus it's not really an option because I have all my other externalized pics in this folder...

  • 1
    I have been unable to reproduce the problem on my TeX Live 2012 linux installation; it worked. Could you add the log file of the external picture for the problem at hand and the various problems mentioned in comments to @Jake's answer? It should state what it tried and where it failed. The log is in pics/*.log Commented Mar 11, 2013 at 20:00
  • @ChristianFeuersänger: I just realized what the problem was: I was trying this in a file that I have used for testing before. So with externalization, it found something and used that instead of my new image. That was the weird stuff I saw. I feel so dumb, I'm sorry... Still, it does not explain why there was no image at all in my main project... Since changing the filename to something random did not have any effect, I don't have a log file either. It's weird, but with \tikzexternalizedisable, my problem is solved. I don't really have to externalize the axes for a pdf image.
    – schnupsi
    Commented Mar 12, 2013 at 8:59
  • Ok, thanks for the note. I admit that this leaves me wondering if there is some open issue remaining... the first part sounds as if cleaning your project was the solution; the second part sounds as if there is still something which prevents you from including the figure. Commented Mar 12, 2013 at 19:28
  • @ChristianFeuersänger: There is no issue left, I checked: Before disabling externalization, I forgot to set a name, and in fact, there is an empty figure0 in my pics folder. That is why changing the filename had no effect because there was something there. That is a different story: Shouldn't the externalization routine see when there have been changes to the figure?
    – schnupsi
    Commented Mar 13, 2013 at 7:55
  • 1
    Thanks for the update. Yes, the externalization compares the TeX code of your figure against the last run. At least in PGF versions after 2.10 -- but 2.10 is the current stable. Commented Mar 13, 2013 at 21:03

1 Answer 1


This problem occurs because the testfile.png is expected to be in the same folder as the .tex file. When you're using the external library with the prefix=pics/ option, that's where the .tex file is, so testfile.png is expected to be in the pics folder as well.

A couple of different ways of fixing this spring to mind:

  • Move the testfile.png to the pics folder.
  • Add \graphicspath{..} to the preamble to tell LaTeX that the images are one folder above the .tex file.
  • Use \addplot graphics ... {../testfile}; to specify that the image is in the folder above.
  • Use an absolute path when specifying the image file name.
  • 1
    Thanks, I didn't think of that. But in fact, I am using a full path because my figure is in a different folder than either my externalization folder or my tex file... One thing that seems to work is putting the whole figure into {\tikzexternaldisable }. But I have another problem now: I cannot change the size of the figure anymore! Just using \includegraphics{../pics/testfile} gives me the size I want, but \addplot graphics ... {../pics/testfile} is only half the width and about 90% the height - no matter what I put into includegraphics={} !!!
    – schnupsi
    Commented Mar 11, 2013 at 17:21
  • 2
    @schnupsi: There are a couple of different issues here: First, if you're really specifying the full path (/home/username/something/testpic), you shouldn't get an error. Could you check the log file (of both the main file and the externalized .tex file) for the exact error message? About the different size: PGFPlots will fit the image to your axis size, which is specified using the width and height options of the axis environment. Do you want the image to be unscaled?
    – Jake
    Commented Mar 11, 2013 at 17:56
  • I used a relative path to my figure folder. It works fine for anything else. There is no error message. I simply did not see a picture. I tried changing the filename to some nonexistent file and nothing happened. With \tikzexternaldisable, it works now. Yes, I want the image unscaled. I did not use any width or height options for the axis. I tried includegraphics={width=500pt} (the width of the image) in the plot options as explained in the pgfplots manual, but nothing happens - even if I change it to 10pt...
    – schnupsi
    Commented Mar 11, 2013 at 18:11
  • 2
    @schnupsi: It says in the manual that the scaling options (like width) passed to the includegraphics key are overwritten and don't have an effect. That key is meant for things like trim. If you want to adjust the size of the image, you have to adjust the size of the axis by adjusting the width option there.
    – Jake
    Commented Mar 11, 2013 at 18:52
  • That's it! I must have overlooked that, thanks a bunch!
    – schnupsi
    Commented Mar 12, 2013 at 8:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .