# Attach local coordinate frame to figure

Using tikz I would like to add a local coordinate frame to a figure (the plane jpeg). If I place the plane in the origin (0,0) it seems to work fine with the following code.

\documentclass[preview, convert]{standalone}

\usepackage{tikz}

\begin{document}

\usetikzlibrary{arrows}
\begin{tikzpicture}[
scale=1,
axis/.style={very thick, ->, >=stealth'}]

\draw[help lines] (0,0) grid (5,5);

\node[anchor=center,rotate=45,opacity=0.5]
(ego) at (0,0) {\includegraphics[scale=0.2]{latex/plane.jpeg}};
\begin{scope}[x={(ego.east)},y={(ego.north)}]
\draw [<->, thick]
(-0.5,1.5) node [left] (y_ego) {$y$} --
(-0.5,0) --
(1.5,0) node [below right] (x_ego) {$x$};
\end{scope}

\end{tikzpicture}
\end{document}


But when I move it to another place (3,3 in this case) the local frame does not get moved as I expected. What am I doing wrong?

How can I attach a local coordinate frame to a figure?

• Welcome to TeX.SE! Please, complete your code snipped to complete small document beginning with \documentclass{...} and with \end {document} on the end. – Zarko Mar 24 '17 at 16:33

• Use default axis for the scope
• Rotate the scope with the same angle as the figure

To easily show that I wrapped your figure in a macro: \myfig that takes the two parameters to show the behavior. Then, I just shift the scope and rotate it using the same amount.

\documentclass[preview, convert]{standalone}

\usepackage{tikz}

\begin{document}
\usetikzlibrary{arrows}

\newcommand{\myfig}[3]{
\node[anchor=center,rotate=#3,opacity=0.5]
(ego) at (#1,#2) {\includegraphics[scale=0.2]{example-image-a}};

\begin{scope}[shift=(ego.center), rotate=#3]
\draw [<->, thick]
(0,1.5) node [left] (y_ego) {$y$} --
(0,0) --
(1.5,0) node [below right] (x_ego) {$x$};
\end{scope}
}

\begin{tikzpicture}[
scale=1,
axis/.style={very thick, ->, >=stealth'}
]
\draw[help lines] (0,0) grid (5,5);

\myfig{0}{0}{45}

\myfig{3}{3}{45}

\myfig{5}{0}{30}
\end{tikzpicture}
\end{document}