# Drawing tikz figure over pgfplots(scaling issue)

I want draw over a plotted graph. In this particular case I want to show a projectile path hitting a wall(gray box). I want the blue path stop at the gray wall.

May be the coordinates of the pgfplots and the coordinates tikz uses are not at same scale.

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{esvect}

\def\FunctionF(#1){tan(30)*(#1)-(9.8*(#1)^2)/(2*(15*cos(30))^2)}%

\begin{document}
\begin{tikzpicture}

\begin{axis}[
xmin=0,
xmax=20,
ymin=0,
ymax=4,
height=4cm,
width=20cm,
hide axis
]
\end{axis}
\draw (-1,0)--(20,0);
\draw[->] (0,0)--node[above]{$\vv{v}$}(30:3);
\draw[fill=black, fill opacity=0.2, black] (10,0) rectangle (10.2,3);
\end{tikzpicture}
\end{document}


• No, the coordinates of the tikzpicture are in general not the same as those of the axis. Try to add \pgfplotsset{compat=1.11} to the preamble, and move the \draw-lines before \end{axis}. Jun 26 '20 at 21:24
• @TorbjørnT. In my case after adding \pgfplotsset{compat=1.11} the document is not finishing building. After about 30 minutes it still is building. Jun 27 '20 at 9:31
• Huh, odd. Don't know why that would happen, and I couldn't even guess without an example demonstrating the behaviour. But nevermind, remove the compat setting then, and instead prefix all the coordinates with axis cs:. That is, instead of \draw (-1,0) ... you have \draw (axis cs:-1,0) ... Jun 27 '20 at 9:34
• Sorry, hadn't noticed the polar coordinate, that might muddle things a bit. Jun 27 '20 at 9:44

This is probably a duplicate of one or more questions, but anyways. The coordinates of an axis environment is in general not the same as the underlying tikzpicture. To draw stuff in axis units, move the stuff inside the axis environment and either

• activate compat=1.11 or some higher version or
• prefix coordinates with axis cs. (i.e. (axis cs:0,0) instead of (0,0))

The latter doesn't work with polar coordinates though, but a workaround for that is to decompose the vector (e.g. drawing lines using polar axis coordinate system in pgfplots).

You said \pgfplotsset{compat=1.11} stopped your document from compiling, so either try activating it for this single axis, by adding it to the options of the environment, or use axis cs. Both are demonstrated below.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{esvect}

\def\FunctionF(#1){tan(30)*(#1)-(9.8*(#1)^2)/(2*(15*cos(30))^2)}%

\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0,
xmax=20,
ymin=0,
ymax=4,
height=4cm,
width=20cm,
hide axis
]

\draw (-1,0)--(20,0);
\draw[->] (0,0)--node[above]{$\vv{v}$}(30:3);
\draw[fill=black, fill opacity=0.2, black] (10,0) rectangle (10.2,3);
\end{axis}

\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[
xmin=0,
xmax=20,
ymin=0,
ymax=4,
height=4cm,
width=20cm,
hide axis
]
\draw[->] (axis cs:0,0) -- node[above]{$\vv{v}$} (axis cs:{3*cos(30)},{3*sin(30});