Graphics, Figures & Tables ⇒ Grid with colored Cells
Grid with colored Cells
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.)
Thank you in advance.
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
Grid with colored Cells
I've tried several ways, and in the end, it turned out to be easier in this way:
Code: Select all
\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}
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