Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

\documentclass[a4paper,fontsize=10pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize[optimize=false,prefix=pics/] 
\tikzset{external/force remake=false}
\usepackage{pgfplots}
\usepackage{graphicx}

\begin{document}

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

\end{document}

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...

share|improve this question
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 –  Christian Feuersänger Mar 11 '13 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 Mar 12 '13 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. –  Christian Feuersänger Mar 12 '13 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 Mar 13 '13 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. –  Christian Feuersänger Mar 13 '13 at 21:03

1 Answer 1

up vote 8 down vote accepted

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.
share|improve this answer
    
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 Mar 11 '13 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 Mar 11 '13 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 Mar 11 '13 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 Mar 11 '13 at 18:52
    
That's it! I must have overlooked that, thanks a bunch! –  schnupsi Mar 12 '13 at 8:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.