# pgfplots axis enlargelimits [duplicate]

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.

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


Any suggestions?

-

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

–  Kurt Sep 28 '12 at 12:38

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]
% 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:

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 coordinates { (-4,1) (1,2) };
\addplot coordinates { (1,1) (1.25,2.5) };
\end{axis}


This will be:

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:

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