使用 \foreach 命令添加节点圆
\begin{tikzpicture}[scale=0.5]
\draw[->] (-10, 0) -- (10, 0) node[right] {$x$};
\draw[->] (0, -10) -- (0, 10) node[above] {$y$};
{
\foreach \n in {8,7,...,-8}
\draw[name path global=a,domain=-8:8,smooth, variable=\y, blue] plot ({\y}, {\n});
{ \foreach \n in {8,7,...,-8}
\draw[name path global=b,rotate=90,domain=-8:8,smooth, variable=\y, green] plot ({\y}, {\n});
\draw[name intersections={of={a} and {b}}](intersection-1) circle (1pt);
}
}
\end{tikzpicture}
答案1
我不确定你需要什么。如果它类似于你的图片,但带有 x、y 轴,你可以执行以下操作:
\documentclass[tikz, border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}[scale=0.5]
\draw[blue,very thin] (-8.5,-8.5) grid (8.5,8.5);
\draw[thick,->] (-10, 0) -- (10, 0) node[right] {$x$};
\draw[thick,->] (0, -10) -- (0, 10) node[above] {$y$};
\foreach \x in {-8,...,8} \foreach \y in {-8,...,8}
\draw[blue,very thin,fill=white] (\x,\y) circle (1pt);
\end{tikzpicture}
\end{document}
答案2
如果您不需要网格的两种颜色(如@Juan的回答中所述),我将使用网格。以下是变体。
\documentclass[tikz]{standalone}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[scale=0.5]
\pgfmathsetmacro\xmin{-8}
\pgfmathsetmacro\xmax{8}
\pgfmathsetmacro\ymin{-8}
\pgfmathsetmacro\ymax{8}
\pgfdeclarelayer{foreground layer}
\pgfsetlayers{main,foreground layer}
\begin{scope}
\draw[->] (\xmin-2, 0) -- (\xmax+2, 0) node[right] {$x$};
\draw[->] (0, \ymin-2) -- (0, \ymax+2) node[above] {$y$};
\foreach \x in {\xmin,...,\xmax}{
\draw [blue] (\x, \ymin) -- (\x, \ymax);
}
\foreach \y in {\ymin,...,\ymax}{
\draw [green] (\xmin, \y) -- (\xmax, \y);
}
\foreach \x in {\xmin,...,\xmax}{
\foreach \y in {\ymin,...,\ymax}{
\fill[red] (\x,\y) circle [radius=2pt];
}}
\end{scope}
\begin{scope}[xshift=22cm]
\draw[->] (\xmin-2, 0) -- (\xmax+2, 0) node[right] {$x$};
\draw[->] (0, \ymin-2) -- (0, \ymax+2) node[above] {$y$};
\draw[step=1cm,blue,very thin] (\xmin, \ymin) grid (\xmax, \ymax);
\foreach \x in {\xmin,...,\xmax}{
\foreach \y in {\ymin,...,\ymax}{
\fill[red] (\x,\y) circle [radius=2pt];
}}
\end{scope}
\begin{scope}[xshift=44cm]
\draw[->] (\xmin-2, 0) -- (\xmax+2, 0) node[right] {$x$};
\draw[->] (0, \ymin-2) -- (0, \ymax+2) node[above] {$y$};
\foreach \x in {\xmin,...,\xmax}{
\draw[name path=a, blue] (\x, \ymin) -- (\x, \ymax);
\foreach \y in {\ymin,...,\ymax}{
\draw[name path=b, green] (\xmin,\y) -- (\xmax,\y);
\begin{pgfonlayer}{foreground layer}
\fill[name intersections={of=a and b}, red](intersection-1) circle (2pt);
\end{pgfonlayer}
}
}
\end{scope}
\end{tikzpicture}
\end{document}