1

I have no idea to plot the following graph. I don't need the bold shade. Can anyone help me. Thank you in advance. enter image description here

2

A simple foreach is enough. The grid without the numbers can also be done with \draw (0,0) grid (6,4); and this can be modified as any other path. You can also specify the step, which in this case is not needed because the drawing uses 1cm and Tikz uses the same value by default.

Since you want custom numbers and you're loading pgfmath through Tikz, you can use arrays. The number 404 is there because you gave me only 4 numbers for the second row, so it was... not found.

Output

enter image description here

Code

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}

\tikzset{
    dot/.style 2 args={fill, circle, inner sep=1pt, label={#1:\scriptsize #2}}
}

\begin{document}
\begin{tikzpicture}

\def\numberlist{{3,0,1,0,2,3,0,2,1,404,2,1,0,6,7,1,1,3,4,5,1,3,2,1,0}} 
\def\maxX{4}
\foreach \x [count=\n] in {0,...,\maxX}{
    \foreach \y in {0,...,4}{
        \pgfmathtruncatemacro\tmp{\n+(\maxX+1)*\y}
        \pgfmathtruncatemacro\num{\numberlist[\tmp-1]}
        \draw[line width=.5pt] (\x,0) -- (\x,4);
        \draw[line width=.5pt] (0,\y) -- (\maxX,\y);
        \node[dot={45}{\num}] at (\x,\y) {};
    }
}

\end{tikzpicture}
\end{document}
  • @Alenano Thank you so much for your answer. How can change the label of a node? – Thomas Edison Sep 3 '16 at 15:47
  • @ThomasEdison It depends. In what way do you want to change them? – Alenanno Sep 3 '16 at 20:53
  • I want to change 1,2,3,4,5 ... to 3,0,1,2,1,.... This sequence does not has any rule. – Thomas Edison Sep 4 '16 at 0:34
  • @ThomasEdison None whatsoever? What's the full sequence of numbers you need? – Alenanno Sep 4 '16 at 0:37
  • I only need to plot in 5x5 grid with label are row 1: 3,0,1,0,2. row 2: 3,0,2,1, row 3: 2,1,0,6,7, row 4: 1,1,3,4,5, row 5: 1,3,2,1,0 – Thomas Edison Sep 4 '16 at 0:41

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.