Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can i use Tikz to draw a picture like this one enter image description here


I tried the following example but was unable to know how to draw cell outlines (borders_

\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}
share|improve this question
    
Do you want to replicate the exact color pattern here, or do you just want something that approximates it? Additionally, questions about how to draw specific graphics that just post an image of the desired result would be greatly improved with an MWE. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. –  Adam Liter Dec 24 '13 at 19:37
    
Thank you for your immediate response. I do not care for the exact colors. Any color that approximates it will be helpful as i can change the colors later using any color dropper. I will try to use the MWE but I am a beginner in latex and this may take some time. –  Dr Adel Dec 24 '13 at 20:03
    
Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. –  Martin Schröder Dec 24 '13 at 20:10
add comment

3 Answers

This uses the idea of Kevin C to put the colours but 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}

enter image description here

Key strokes could have been further reduced, but I left it as is.

Engage crystal ball:

Taking the code from OP (posted as an answer), One has to add vertical lines as \begin{tabular}{|*{12}{R|}} and horizontal lines through \hlines. F change the color of the lines, load colortbl and issue \arrayrulecolor{green}. I have also changed the \fboxsep to 8mm so that things don;t go out of page. For tables I always prefer \centering over \begin{center}.

Full code:

\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}

enter image description here

share|improve this answer
add comment

I'd use a TikZ matrix to draw this.

Code

\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}

Output

enter image description here

share|improve this answer
add comment

Depending on the exact requirements, the following may suffice:

\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}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.