[Tex/LaTex] Drawing a multicolored grid using TikZ

tikz-pgf

How can I draw a grid similar to the one below in the question answer?

Fill a grid with TikZ

But I can select different fill colors for the separate cells?

I need to be able to color (fill) in the separate nodes in the grid. I tried using this, but for some reasons there's some weird padding on the fill

\documentclass{article} 
\usepackage{algorithmic}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{tikz}
\title{Title} 
\author{User} 
\begin{document} 
\begin{tikzpicture}
    \draw[step=0.5cm,color=black] (-1,-1) grid (1,1);
    \node[fill=green] at (-0.75,+0.75) {};
    \node at (-0.25,+0.75) {};
    \node at (+0.25,+0.75) {};
    \node at (+0.75,+0.75) {};
    \node at (-0.75,+0.25) {};
\end{tikzpicture}
\end{document}

Best Answer

\documentclass[tikz,border=2mm]{standalone}

\begin{document}

\begin{tikzpicture}[every node/.style={minimum size=.5cm-\pgflinewidth, outer sep=0pt}]
    \draw[step=0.5cm,color=black] (-1,-1) grid (1,1);
    \node[fill=green] at (-0.75,+0.75) {};
    \node[fill=red] at (-0.25,+0.75) {};
    \node[fill=orange] at (+0.25,+0.75) {};
    \node[fill=yellow] at (+0.75,+0.75) {};
    \node[fill=purple!70] at (-0.75,+0.25) {};
\end{tikzpicture}

\end{document}

enter image description here

Update:

Command \draw[step=0.5cm,color=black] (-1,-1) grid (1,1); draws the grid. step fixes element size and coordinates before and after grid define grid dimensions. If you want a grid with three rows and eight columns with 0.5cm squares and bottom left corner at (0,0), use

\draw[step=0.5cm,color=black] (0,0) grid (4,1.5);

as in

\documentclass[tikz,border=2mm]{standalone}

\begin{document}

\begin{tikzpicture}[every node/.style={minimum size=.5cm-\pgflinewidth, outer sep=0pt}]
    \draw[step=0.5cm,color=black] (0,0) grid (6,1.5);
    \node[fill=green] at (0.25,+1.25) {};
    \node[fill=red] at (0.25,+0.25) {};
    \node[fill=orange] at (+3.25,+0.75) {};
    \node[fill=orange] at (+2.75,+0.75) {};
    \node[fill=yellow] at (+5.75,+1.25) {};
    \node[fill=purple!70] at (5.75,+0.25) {};
\end{tikzpicture}

\end{document}

enter image description here