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:


And my code looks something like.

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

Any suggestions?

marked as duplicate by Jake, user11232, 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.


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:


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:

  \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) };

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.

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

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

  • 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

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