格子图

格子图

我必须在 LaTex 中绘制下面的图形,但我不知道代码。 在此处输入图片描述

答案1

Tikz 可以实现一种简单的方法。以下结果是

在此处输入图片描述

上述输出的代码是

 \documentclass[border={10pt}]{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}
    [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        dot/.style={circle,draw=black, fill,inner sep=1pt},
    ]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\foreach \x in {0,...,5}{
    \node[dot] at (\x,5){ };
    \node[dot] at (\x,4){ };
}

\foreach \x in {.2,1.2}
    \draw[thick] (\x,4) -- (\x+.6,4);
\foreach \x in {3.2,4.2}
    \draw[thick] (\x,2) -- (\x+.6,2);
\foreach \y in {1.8,.8}
    \draw[thick] (5,\y) -- (5,\y-.6);
\draw[thick] (2,3.8) -- (2,3.8-.6);
\draw[thick] (3,2.8) -- (3,2.8-.6);
\draw[thick] (2.2,3) -- (2.2+.6,3);
\foreach \x in {2,...,5}
    \node[dot] at (\x,3){};
\foreach \x in {3,...,5}
    \node[dot] at (\x,2){};

\foreach \x in {1,...,4}
    \draw (\x,.1) -- node[below,yshift=-1mm] {\x} (\x,-.1);
\node[below,yshift=-1mm] at (5,0) {5};
\node[below,xshift=-2mm,yshift=-1mm] at (0,0) {0};

\foreach \y in {1,...,3}
    \draw (.1,\y) -- node[below,xshift=-2mm] {\y} (-.1,\y);
\node[below,xshift=-2mm] at (0,4) {4};
\node[below,xshift=-2mm] at (0,5) {5};  
\node[dot] at (5,1){};  
\node[dot] at (5,0){};      
\draw[->,thick,-latex] (0,-1) -- (0,6);
\draw[->,thick,-latex] (-1,0) -- (6,0);
\end{tikzpicture}

\end{document}

相关内容