标记网格中的点

标记网格中的点

我正在尝试使用 tikzpicture 构建一个网格,但标签位于 (0,0)、(0,1)、(0,2) 等,如下所示

\begin{tikzpicture}[scale=1]
\draw[step=1cm,lightgray,very thin] (0,0) grid (5,5);
\filldraw[gray] (0,0) node {\tiny $(0,0)$};
\filldraw[gray] (0,1) node {\tiny $(0,1)$};
\filldraw[gray] (1,0) node {\tiny $(1,0)$};
\filldraw[gray] (1,1) node {\tiny $(1,1)$};
\filldraw[gray] (2,0) node {\tiny $(2,0)$};
%... and so on ...
\end{tikzpicture}

例子

但是,写节点太费时间了。有没有更简单的方法来标记点?我想象它应该是这样的

\foreach \x in {0, 1, ..., 5}
\foreach \y in {0,...,5}
node {\tiny $(\x,\y)$}

谢谢你的时间!

答案1

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
    \begin{tikzpicture}
        \foreach \x in {1,...,7}
            \foreach \y in {1,...,5}
                \fill (\x,\y) circle[radius=1pt] node[above right] {\tiny $(\x,\y)$};
    \end{tikzpicture}
\end{document}

节点和坐标

或者像图片中那样在网格上:

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
    \begin{tikzpicture}
        \draw[gray!50] (0,0) grid (7,5);
        \foreach \x in {0,...,7}
            \foreach \y in {0,...,5}
                \node at (\x,\y) {\tiny $(\x,\y)$};
    \end{tikzpicture}
\end{document}

节点和坐标 2

答案2

\documentclass{article}
\usepackage{tikz,calc}

\begin{document}
    
    \begin{tikzpicture}[scale=1.5]
        \draw[gray!30] (-3,-3) grid (3,3);
        \draw[-latex,blue] (-3.4,0)--(3.4,0) node[right] (x) {\footnotesize $x$};
        \draw[-latex,blue] (0,-3.4)--(0,3.4) node[above] (y) {\footnotesize $y$};
        \foreach \i in {-3,-2,...,3}{
            \foreach \j in {-3,-2,...,3}{
                %\pgfmathsetmacro\h{int(\i+\j)};
                \filldraw[black] (\i,\j) circle(.8pt);
                \node[blue,right] at (\i,\j+.1) (\i) {\tiny (\i,\j)};
                
            }
        } 
    \end{tikzpicture}     
\end{document} 

输出:

在此处输入图片描述

相关内容