I'm trying to plot an image, which is basically a matrix of intensity values. I want the colour scheme to range from black for the lowest to white for the highest value, with a defined colour in the middle. (I based my approach on this answer to a similar question.)
Here is a MWE:
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=1]
\foreach \y [count=\n] in { %this is normally a VERY large matrix
{0,50},
{75,100},
} {\foreach \x [count=\m] in \y {\fill[white!\x!red!\x!black] (1*\n,-1*\m) rectangle ++(1,1);}}
\end{tikzpicture}
\end{document}
The problem is that my values in absolute terms range from 0 to about 400 and in my current approach I need to normalise them to a range from 0 to 100. This technically works, however, this means that I loose 3/4 of my colour information. Unfortunately, the data is very sensitive and I am now looking for a way to use a larger range.
My new approach is dividing the colour scheme into two parts, so that I can use at least values from 0 to 200. However, this does not seem to work, and I am not that proficient in using if-commands in LaTeX. (I am aware of this answer by Christian Feuersänger to the same question reference above, but suffice it to say that I do not fully understand it and therefore struggle with adapting it to my case.)
\documentclass[tikz]{standalone}
\usepackage{calc}
\usepackage{ifthen}
\begin{document}
\begin{tikzpicture}[scale=1]
\foreach \y [count=\n] in {
{0,100},
{150,200},
}
{\foreach \x [count=\m] in \y {
\fill[\ifnum\x<100 {white!\x!red} \else {red!{\x/2}!black}\fi] (1*\n,-1*\m) rectangle ++(1,1);
}}
\end{tikzpicture}
\end{document}
Can someone tell me, what my mistake is or maybe even how to solve this more efficiently?
