\addplot 和 \draw

\addplot 和 \draw

我使用 Geogebra 生成了一些 pgf/tikz 代码,效果很好

\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}

另一方面,我根据坐标文件绘制图形,效果很好

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

我似乎无法将其合并到一个图形中(相同的坐标系)。如果没有轴环境,\addplot 就无法工作,而 \draw 会产生很多错误,并且在放入轴环境内时不会遵循相同的坐标。

我知道我对 pgf/tikz 的理解存在很大差距,但如何才能成功连接图表呢?

答案1

您可以将axis环境包含在 Geogebra 生成的环境中tikzpicture。要对齐坐标系,请anchor=originaxis选项中设置,并选择相同的xy长度:

\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}

相关内容