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.

Possible Duplicate:
Image with axis

I want to place an image against the edge of an axis frame, but because of the (unknown to me) value of the enlarged limits, I can't find the coordinates both where to place it and what the height should be.

This is what I'm talking about:

Plot

And my code looks something like.

\begin{tikzpicture}
\begin{axis}
\addplot[color=colora] file {data.dat};
\node[anchor=base east] at (axis cs:0,0) {\includegraphics[height=1cm,keepaspectratio]{myimage.png}};
\end{axis}
\end{tikzpicture}

Any suggestions?

share|improve this question
3  
Welcome to TeX.sx!. –  Kurt Sep 28 '12 at 12:38
add comment

marked as duplicate by Jake, Harish Kumar, egreg, Tom Bombadil, Paul Gaborit Sep 28 '12 at 21:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

What you are looking for is the enlargelimits=false which should always be used when inserting graphics. Also know that you should explicitly add limits for your plot! pgfplots can not read that from the image. Thus always set:

xmin
xmax
ymin
ymax

when using graphics.

However, I would recommend you to look into the \addplot graphics command which can basically do what you want. And is a lot easier to maintain for sizes of the graphics, etc.

Take the example in the manual and do like this:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[small, enlargelimits=false,axis on top]
    \addplot graphics [xmin=-3,xmax=3,ymin=-3,ymax=3] {external1};
    % Add a second graph on top of the graphics (be sure to have
    % graphics first!
    \addplot coordinates { (1,1) (1,2) };
  \end{axis}
\end{tikzpicture}
\end{document}

This will look like this:

enter image description here

If you instead wish to have it clammed at the right side, just do the same, but specify the extra filling in the axis environment. This you do by using enlarge x limits={abs value=<extra x space>,lower}. lower can also be upper if needed.

\begin{axis}[small,enlargelimits=false,
    enlarge x limits={abs value=2,lower},axis on top]
  \addplot graphics [xmin=-3,xmax=3,ymin=-3,ymax=3] {external1};
  \addplot coordinates { (-4,1) (1,2) };
  \addplot coordinates { (1,1) (1.25,2.5) };
\end{axis}

This will be:

enter image description here

The last thing is that if you want it in between the sides. Then simply specify the limits in the axis environment explicitly.

As Jake mentioned the axis equal image key can be used to keep aspect ratio. It conserves the limits (unlike axis equal)

Try and insert axis equal image and you will get:

enter image description here

share|improve this answer
2  
Very nice! Maybe it's also a good idea to mention the axis equal image key, which ensures that the image is not squashed. –  Jake Sep 28 '12 at 12:40
    
@Jake added, however, they have some troubles retaining the axis limits when adding that key. :) For obvious reasons... –  zeroth Sep 28 '12 at 12:47
2  
Thanks! Though I actually meant axis equal image, which is slightly different from axis equal=true in that the unit vectors in x and y direction do not have to be the same. –  Jake Sep 28 '12 at 12:56
    
@Jake ah yes of course (exactly what solves the problem of axis limits), I read your comment much too fast! :) –  zeroth Sep 28 '12 at 12:58
add comment

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