[Tex/LaTex] \addplot and \draw

pgfplotstikz-pgf

I generated some pgf/tikz code with Geogebra with good result

\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw[->,color=black] (-6.72,0) -- (7.8,0);
\foreach \x in {-6,-4,-2,2,4,6}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0,-3.75) -- (0,7.03);
\foreach \y in {-2,2,4,6}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw(3,-1) circle (2cm);
\fill [color=black] (-3,0) circle (1.5pt);
\draw [color=black] (-2.9,-0.26)-- ++(-1.5pt,-1.5pt) -- ++(3.0pt,3.0pt) ++(-3.0pt,0) -- ++(3.0pt,-3.0pt);
\end{tikzpicture}

On the other hand I draw a figure based on a coordinate file, works fine

\begin{tikzpicture}[]
\begin{axis}[axis x line=none, axis y line=none]
\addplot[smooth, color=black] file[]{coords.txt};
\end{axis}
\end{tikzpicture}

I can't seem to join this in one graph (same coordinate system). \addplot doesn't work without the axis environment and \draw produces a lot of errors and don't follow the same coordinates when put inside the axis environment.

I know there's some big gap in my understanding of pgf/tikz but how can the graphs be succesfully joined?

Best Answer

You can include the axis environment in the tikzpicture generated by Geogebra. To align the coordinate systems, set anchor=origin in the axis options, and choose the same x and y lengths:

\documentclass{article}
\usepackage{tikz, pgfplots}
\usetikzlibrary{arrows}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw[->,color=black] (-6.72,0) -- (7.8,0);
\foreach \x in {-6,-4,-2,2,4,6}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0,-3.75) -- (0,7.03);
\foreach \y in {-2,2,4,6}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw(3,-1) circle (2cm);
\fill [color=black] (-3,0) circle (1.5pt);
\draw [color=black] (-2.9,-0.26)-- ++(-1.5pt,-1.5pt) -- ++(3.0pt,3.0pt) ++(-3.0pt,0) -- ++(3.0pt,-3.0pt);

\begin{axis}[
    anchor=origin,  % Align the origins
    x=1cm, y=1cm,   % Set the same unit vectors
    hide axis
]
\addplot [mark=*, color=red] table {
4 5
-2 -2
-4 0
};
\end{axis}
\end{tikzpicture}
\end{document}