This seems like a really stupid question, but I cannot find the answer...
I am trying to make a contiguous grid of coloured blocks using Tikz, much like in this question, but in my case, the colours to be filled in are grayscale values in the real number range [0.0,1.0], i.e. the 'gray' colour model listed in the xcolor package documentation. The values (and, in theory, the figures) are generated programmatically and could be any arbitrary number between 0 and 1 (inclusive), so it won't make sense to use a handful of definecolor commands at the start. Instead, my current plan is to overwrite the fill for each node as my script writes it out to the file.
For a minimum working example, the below produces something that looks like what I want (see the image below it), except I cannot work out how to get the correct sort of grayscale settings. Using the approach I thought might work, the first three cells just produce white (I suspect it is using the Gray system, with an integer range of [0,255]). The latter six create the sort of results I'm looking for, but the fill colours are not specified in a useful way.
\documentclass[tikz]{standalone} \usetikzlibrary{positioning} \begin{document} \begin{tikzpicture}[outer sep=0pt,minimum size=1cm] \selectcolormodel{gray} \node [fill={gray!0.1}] at (0,0) {}; \node [fill={gray!0.2}] at (0,-1) {}; \node [fill={gray!0.3}] at (0,-2) {}; \node [fill={rgb:black,4;white,8}] at (1,0) {}; \node [fill={rgb:black,5;white,7}] at (1,-1) {}; \node [fill={rgb:black,6;white,6}] at (1,-2) {}; \node [fill={rgb:black,7;white,5}] at (2,0) {}; \node [fill={rgb:black,8;white,4}] at (2,-1) {}; \node [fill={rgb:black,9;white,3}] at (2,-2) {}; \end{tikzpicture} \end{document} I have also tried out such commands as gray:0.1, or using \PassOptionsToPackage{gray}{xcolor} and then something like just 0.1, but all of those seem to hit compilation errors.
Alternatively, I also tried using the 'matrix' option of Tikz, as below, but that didn't seem to permit any colouring of the grid cells (the visible lines come from using the node=draw option).
\documentclass[tikz]{standalone} \usetikzlibrary{positioning} \begin{document} \begin{tikzpicture}[nodes=draw] \matrix { \node { }; [fill={rgb:black,2;white,10}]; & \node {}; [fill={rgb:black,3;white,9}]; & \node {}; [fill={rgb:black,4;white,8}]; \\ \node { }; [fill={rgb:black,5;white,7}]; & \node {}; [fill={rgb:black,6;white,6}]; & \node {}; [fill={rgb:black,7;white,5}]; \\ \node { }; [fill={rgb:black,2;white,10}]; & \node {}; [fill={rgb:black,3;white,9}]; & \node {}; [fill={rgb:black,4;white,8}]; \\ }; \end{tikzpicture} \end{document} How can I create a grid of grayscale coloured blocks using Tikz, with gray colour values in the real number range [0.0,1.0] specified individually for each cell?




colorletfor example) with the color mixing (thecolor!number!color2notation). To have a grey scale with the second one you need to useblack!xxwherexxis in the range 0-100 (the second color is white when not specified)