# How can I place an external image of given dimensions at the center of a pgfplot?

Let's say I would like to place a certain picture at the center of my plot, such that it matches some given dimension on the scale of my pgfplot. I was thinking at first that I could include an external image in the standard procedure, with the key axis equal image. However, I would like to draw around the image in the middle, so that the axes need to remain scalable. I think that the latter option would thus not work.

To give you a more concrete example, I want to draw planar orbits around the Moon. To give a sense of scale, I want to draw the Moon in the middle of the plot, and then draw any kinds of orbit.

Say I want to draw a simple circular orbit of 200 km around the Moon, like this:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\rMoon}{1737.4}
\pgfmathsetmacro{\rOrbit}{200}
\begin{axis}[
axis equal
]
({(\rMoon+\rOrbit) * cos(deg(x))}, {(\rMoon+\rOrbit) * sin(deg(x))});
\end{axis}
\end{tikzpicture}
\end{document}


The output is:

How can I place a picture of the Moon in the middle? The radius of the Moon is 1737.4 km.

You can use the following asset:

-

This is what \addplot graphics is for. If you add the image using

\addplot graphics [xmin=-\rMoon, xmax=\rMoon, ymin=-\rMoon, ymax=\rMoon] {moon.png};


it is automatically scaled and positioned correctly:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\rMoon}{1737.4}
\pgfmathsetmacro{\rOrbit}{200}
\begin{axis}[
axis equal,
]
\addplot graphics [xmin=-\rMoon, xmax=\rMoon, ymin=-\rMoon, ymax=\rMoon] {moon.png};
({(\rMoon+\rOrbit) * cos(deg(x))}, {(\rMoon+\rOrbit) * sin(deg(x))});
\end{axis}
\end{tikzpicture}
\end{document}

-

With manually scaling with your image given in question:

\documentclass{article}

\usepackage{pgfplots,graphicx}
\pgfplotsset{compat=1.9}

\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\rMoon}{1737.4}
\pgfmathsetmacro{\rOrbit}{200}
\begin{axis}[
axis equal
]
({(\rMoon) * cos(deg(x))}, {(\rMoon) * sin(deg(x))});
\node (label) at (axis cs:0,0) {\includegraphics[scale=0.387]{moon.png}};

I could not find any scaling method relative to cs coordinate in pgfplots yet. But I will try. My scaling is fit to your \rMoon+\rOrbit values. –  ferahfeza May 17 at 14:36
Now fit to \rMoon but it is not yet automated for scaling. –  ferahfeza May 17 at 14:52