8

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?

1
  • I think you can include line \draw plot[smooth] file {coords.txt} in your geogebra tikzpicture code and will get what you want. – Ignasi Aug 14 '13 at 9:30
14

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}
1
  • 1
    Thank you, the axis options you provided made everything work! – Anders Aug 14 '13 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.