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.

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
            ]
            \addplot[samples=100, domain=0:2*pi] 
            ({(\rMoon+\rOrbit) * cos(deg(x))}, {(\rMoon+\rOrbit) * sin(deg(x))}); 
        \end{axis}
    \end{tikzpicture}
\end{document}

The output is:

Orbit

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:

Moon

share|improve this question

2 Answers 2

up vote 4 down vote accepted

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};
            \addplot[samples=100, domain=0:2*pi] 
            ({(\rMoon+\rOrbit) * cos(deg(x))}, {(\rMoon+\rOrbit) * sin(deg(x))}); 
        \end{axis}
    \end{tikzpicture}
\end{document}
share|improve this answer

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
            ]
        \addplot[samples=100, domain=0:2*pi] 
            ({(\rMoon) * cos(deg(x))}, {(\rMoon) * sin(deg(x))}); 
        \node (label) at (axis cs:0,0) {\includegraphics[scale=0.387]{moon.png}};
        \addplot[samples=100, domain=0:2*pi] 
            ({(\rMoon+\rOrbit) * cos(deg(x))}, {(\rMoon+\rOrbit) * sin(deg(x))}); 
        \end{axis}

    \end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Thanks. A few remarks and questions. a) The Moon seems to be too large now. Is it really exactly sized as it should be? b) The orbit is not drawn anymore. c) Can this not be automated? That would make my life a whole lot easier, because I need to draw tons of orbits. –  Ingo May 17 at 14:29
    
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
    
Thanks for trying around. I also gave it a shot, but until now couldn't find any way. –  Ingo May 17 at 14:45
    
Now fit to \rMoon but it is not yet automated for scaling. –  ferahfeza May 17 at 14:52

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.