Código

Código

¿Cómo puedo usar TikZ para hacer un dibujo como este? ingrese la descripción de la imagen aquí


Probé el siguiente ejemplo pero no pude saber cómo dibujar los contornos de las celdas (bordes).

\documentclass[12pt,a4paper]{article}
\usepackage[left=0cm,right=0cm,top=0cm,bottom=0cm]{geometry}
\usepackage{tikz}
\usepackage{collcell}

\newcommand*{\MinNumber}{0}%
\newcommand*{\MaxNumber}{1}%

\newcommand{\ApplyGradient}[1]{%
        \pgfmathsetmacro{\PercentColor}{100.0*(#1-\MinNumber)/(\MaxNumber-\MinNumber)}
        \hspace{-0.33em}\colorbox{red!\PercentColor!black}{}
}

\newcolumntype{R}{>{\collectcell\ApplyGradient}c<{\endcollectcell}}
\renewcommand{\arraystretch}{0}
\setlength{\fboxsep}{10mm} % box size
\setlength{\tabcolsep}{0pt}

\begin{document}
\begin{table}[ht]
\begin{center}
\begin{tabular}{*{12}{R}}
0.03 & 0.34 & 0.41 & 0.25 & 0.89 & 0.49 & 0.79 & 0.83 & 0.82 & 0.94 & 0.34 & 0.41 \\
0.49 & 0.25 & 0.80 & 0.83 & 0.93 & 0.25 & 0.82 & 0.80 & 0.35 & 0.00 & 0.25 & 0.80 \\
0.21 & 0.13 & 0.53 & 0.07 & 1.00 & 0.66 & 0.07 & 0.18 & 0.73 & 0.05 & 0.13 & 0.53 \\
0.81 & 0.49 & 0.27 & 0.07 & 0.57 & 0.12 & 0.26 & 0.39 & 0.57 & 0.80 & 0.49 & 0.27 \\
0.23 & 0.31 & 0.90 & 0.03 & 0.18 & 0.60 & 0.49 & 0.02 & 0.44 & 0.50 & 0.31 & 0.90 \\
0.40 & 0.91 & 0.84 & 0.88 & 0.04 & 0.59 & 0.75 & 0.91 & 0.69 & 0.88 & 0.91 & 0.84 \\
0.36 & 0.12 & 0.92 & 0.73 & 0.12 & 0.58 & 0.42 & 0.89 & 0.15 & 0.50 & 0.12 & 0.92 \\
0.93 & 0.07 & 0.57 & 0.43 & 0.12 & 0.70 & 0.54 & 0.25 & 0.06 & 0.57 & 0.07 & 0.57 \\
0.09 & 0.98 & 0.46 & 0.83 & 0.69 & 0.56 & 0.08 & 0.77 & 0.40 & 0.88 & 0.98 & 0.46 \\
0.81 & 0.49 & 0.27 & 0.07 & 0.57 & 0.12 & 0.26 & 0.39 & 0.57 & 0.80 & 0.49 & 0.27 \\
0.36 & 0.12 & 0.92 & 0.73 & 0.12 & 0.58 & 0.42 & 0.89 & 0.15 & 0.50 & 0.12 & 0.92 \\
0.93 & 0.07 & 0.57 & 0.43 & 0.12 & 0.70 & 0.54 & 0.25 & 0.06 & 0.57 & 0.07 & 0.57 \\
0.09 & 0.98 & 0.46 & 0.83 & 0.69 & 0.56 & 0.08 & 0.77 & 0.40 & 0.88 & 0.98 & 0.46 \\
0.81 & 0.49 & 0.27 & 0.07 & 0.57 & 0.12 & 0.26 & 0.39 & 0.57 & 0.80 & 0.49 & 0.27 \\
0.09 & 0.98 & 0.46 & 0.83 & 0.69 & 0.56 & 0.08 & 0.77 & 0.40 & 0.88 & 0.98 & 0.46 \\
0.07 & 0.44 & 0.65 & 0.46 & 0.65 & 0.75 & 0.80 & 0.56 & 0.89 & 0.50 & 0.44 & 0.65 \\
\end{tabular}
\end{center}
\end{table}
\end{document}

Respuesta1

Usaría un TikZ matrixpara dibujar esto.

Código

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,backgrounds}
\begin{document}
\begin{tikzpicture}
  \matrix(m)[matrix of nodes,nodes in empty cells,
  nodes={inner sep=20pt,draw={green!20!yellow},line width=2pt},
  row sep=-\pgflinewidth,
  column sep=-\pgflinewidth,
  ]{
    &&&&&&&&&&&\\
    &&&&&&&&&&&\\
    &&&&&&&&&&&\\
    &&&&&&&&&&&\\
    &&&&&&&&&&&\\
    &&&&&&&&&&&\\
    &&&&&&&&&&&\\
    &&&&&&&&&&&\\
    &&&&&&&&&&&\\
    &&&&&&&&&&&\\
    &&&&&&&&&&&\\
    &&&&&&&&&&&\\
  };
  \begin{scope}[on background layer]
  \foreach \i in {1,...,12} \foreach \j in {1,...,12}{
    \pgfmathrandominteger\x{10}{70}
    \node[fill=black!\x!white,inner sep=20pt]at(m-\i-\j){};
  }
  \end{scope}
\end{tikzpicture}
\end{document}

Producción

ingrese la descripción de la imagen aquí

Respuesta2

Este usa la idea de Kevin C para poner los colores pero no matrix.

\documentclass[border=2pt,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  %% draw the color boxes
  \foreach \i in {0.5,...,11.5} {
  \foreach \j in {0.5,...,11.5}{
    \pgfmathrandominteger\x{10}{70}
    \node[fill=black!\x!white,inner sep=0pt,minimum width=1cm,minimum height=1cm]at(\i,\j){};
  }
  }
  %% draw the borders
  \foreach \x in {0,1,...,12}{
    \draw[green!20!yellow,line width=2pt] (\x,0) -- (\x,12);
    }
  \foreach \y in {0,1,...,12}{
    \draw[green!20!yellow,line width=2pt] (0,\y) -- (12,\y);
    }
\end{tikzpicture}
\end{document}

ingrese la descripción de la imagen aquí

Las pulsaciones de teclas se podrían haber reducido aún más, pero lo dejé como está.

Engranar bola de cristal:

Tomando el código de OP (publicado como respuesta), hay que agregar líneas verticales como \begin{tabular}{|*{12}{R|}}y líneas horizontales hasta \hlines. F cambia el color de las líneas, carga colortbly emite \arrayrulecolor{green}. También he cambiado el \fboxseppara 8mmque las cosas no se salgan de la página. Para tables siempre prefiero \centeringantes que \begin{center}.

Código completo:

\documentclass[12pt,a4paper]{article}
\usepackage[left=0cm,right=0cm,top=0cm,bottom=0cm]{geometry}
\usepackage{tikz}
\usepackage{collcell,colortbl}

\newcommand*{\MinNumber}{0}%
\newcommand*{\MaxNumber}{1}%

\newcommand{\ApplyGradient}[1]{%
        \pgfmathsetmacro{\PercentColor}{100.0*(#1-\MinNumber)/(\MaxNumber-\MinNumber)}
        \hspace{-0.33em}\colorbox{red!\PercentColor!black}{}
}

\newcolumntype{R}{>{\collectcell\ApplyGradient}c<{\endcollectcell}}
\renewcommand{\arraystretch}{0}
\setlength{\fboxsep}{8mm} % box size
\setlength{\tabcolsep}{0pt}
\setlength{\arrayrulewidth}{2pt}
\arrayrulecolor{green}

\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{|*{12}{R|}}\hline
0.03 & 0.34 & 0.41 & 0.25 & 0.89 & 0.49 & 0.79 & 0.83 & 0.82 & 0.94 & 0.34 & 0.41 \\\hline
0.49 & 0.25 & 0.80 & 0.83 & 0.93 & 0.25 & 0.82 & 0.80 & 0.35 & 0.00 & 0.25 & 0.80 \\\hline
0.21 & 0.13 & 0.53 & 0.07 & 1.00 & 0.66 & 0.07 & 0.18 & 0.73 & 0.05 & 0.13 & 0.53 \\\hline
0.81 & 0.49 & 0.27 & 0.07 & 0.57 & 0.12 & 0.26 & 0.39 & 0.57 & 0.80 & 0.49 & 0.27 \\\hline
0.23 & 0.31 & 0.90 & 0.03 & 0.18 & 0.60 & 0.49 & 0.02 & 0.44 & 0.50 & 0.31 & 0.90 \\\hline
0.40 & 0.91 & 0.84 & 0.88 & 0.04 & 0.59 & 0.75 & 0.91 & 0.69 & 0.88 & 0.91 & 0.84 \\\hline
0.36 & 0.12 & 0.92 & 0.73 & 0.12 & 0.58 & 0.42 & 0.89 & 0.15 & 0.50 & 0.12 & 0.92 \\\hline
0.93 & 0.07 & 0.57 & 0.43 & 0.12 & 0.70 & 0.54 & 0.25 & 0.06 & 0.57 & 0.07 & 0.57 \\\hline
0.09 & 0.98 & 0.46 & 0.83 & 0.69 & 0.56 & 0.08 & 0.77 & 0.40 & 0.88 & 0.98 & 0.46 \\\hline
0.81 & 0.49 & 0.27 & 0.07 & 0.57 & 0.12 & 0.26 & 0.39 & 0.57 & 0.80 & 0.49 & 0.27 \\\hline
0.36 & 0.12 & 0.92 & 0.73 & 0.12 & 0.58 & 0.42 & 0.89 & 0.15 & 0.50 & 0.12 & 0.92 \\\hline
0.93 & 0.07 & 0.57 & 0.43 & 0.12 & 0.70 & 0.54 & 0.25 & 0.06 & 0.57 & 0.07 & 0.57 \\\hline
0.09 & 0.98 & 0.46 & 0.83 & 0.69 & 0.56 & 0.08 & 0.77 & 0.40 & 0.88 & 0.98 & 0.46 \\\hline
0.81 & 0.49 & 0.27 & 0.07 & 0.57 & 0.12 & 0.26 & 0.39 & 0.57 & 0.80 & 0.49 & 0.27 \\\hline
0.09 & 0.98 & 0.46 & 0.83 & 0.69 & 0.56 & 0.08 & 0.77 & 0.40 & 0.88 & 0.98 & 0.46 \\\hline
0.07 & 0.44 & 0.65 & 0.46 & 0.65 & 0.75 & 0.80 & 0.56 & 0.89 & 0.50 & 0.44 & 0.65 \\\hline
\end{tabular}
\end{table}
\end{document}

ingrese la descripción de la imagen aquí

Respuesta3

Dependiendo de los requisitos exactos, lo siguiente puede ser suficiente:

\documentclass[tikz,border=0.125cm]{standalone}
\begin{document}
\tikz\foreach \i in {0,...,9}
  \foreach \j [evaluate={\k=rnd*75;}] in {0,...,9}
    \filldraw [fill=gray!\k, draw=green!50!brown, ultra thick]
      (\j,\i) rectangle +(1, 1);
\end{document}

ingrese la descripción de la imagen aquí

información relacionada