## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ Grid with colored Cells

Information and discussion about graphics, figures & tables in LaTeX documents.
tlapeg07
Posts: 2
Joined: Wed Jun 05, 2013 6:54 pm

### Grid with colored Cells

Hello,

I would like to build a grid and to specify the color of each cell. The grid is very large so I want to do it with file data. I have absolutely no idea of how to do it. Do you have any idea ?

The idea is to obtain in LaTeX what you obtain with Excel when you use the conditional formatting on a grid of values. Here I do not want to draw the values, but only the corresponding color (there is no place to write the numbers.)

Tags:

tom
Posts: 73
Joined: Thu Apr 18, 2013 4:02 am
Hi,

That's an interesting question. You could make your life easier and use e.g. R to plot a heat map. If you rather do it in TeX, I recommend using pgf (TiKZ). You can start from here and read your data as shown here.

Let me know if you get stuck.

tlapeg07
Posts: 2
Joined: Wed Jun 05, 2013 6:54 pm
Hello,

I've tried several ways, and in the end, it turned out to be easier in this way:
\pgfmathsetmacro{\minval}{0}\pgfmathsetmacro{\maxval}{2}\pgfmathsetmacro{\colstep}{100/(\maxval-\minval)}\begin{tikzpicture}[scale=0.3]\foreach \x/\y/\z in {1/0/1, 22/0/1, 40/0/1, 53/0/1, ...187/99/1 }{\pgfmathsetmacro{\ptcol}{\colstep*(\z-\minval)}\fill[gray!\ptcol!white] (\x/4-0.25,\y/4-0.25) rectangle (\x/4,\y/4);}\draw (-0.25,-0.25) rectangle (200/4-0.25, 100/4-0.25);\end{tikzpicture}

However, it is difficult to show more than 5000 cells (=5000 lines of data).
To increase the number of cells that I can show, I used a gray to white gradient color. Thus, I show gray and light gray cells, but there is no need to specify the white cells, which correspond then to the background.

Hope it helps someone else.
Bye