Ok, this is probably an incredibly trivial question for anyone who knows more about xcolor or pgf or TikZ or whatever really. I tried to use a hue scale for a heat map/color matrix with values 0<=x<=1. I based this heavily on this answer by adn:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{pgfplotstable}
\usepackage{xstring}
\pgfplotstableset{
color cells/.style={
col sep=comma,
string type,
postproc cell content/.code={%
\pgfkeysalso{@cell content=\rule{0cm}{2.4ex}\IfDecimal{##1}{%
\cellcolor[hsb]{##1,.7,1.}}{}##1}%
},
columns/x/.style={
column name={},
postproc cell content/.code={}
}
}
}
\begin{document}
\begin{table}\caption{Correlation or something}
\centering
\pgfplotstabletypeset[color cells]{
x,a,b,c,d
a,0.9,0.3,-.1,0
b,0,.8,.6,.4
c,1,0.2,.95,.5
d,0,.1,.7,.85
}
\end{table}
\end{document}
This looks like this:

Colorful, but it does what it's supposed to do, even for small negative numbers which aren't supposed to exist ... except:

For a value of 1 the hue wraps around and is back to 0/red again. I tried to subtract a tiny value or multiply the cell content internally by .99 or something but I simply failed to do any arithmetic here.
PS: If you can recommend any good documentation for xcolor, pgf and the like, that'd be great, too. Maybe next time I won't have to ask such stupid questions then.
Edit:
Ok, I didn't do my homework very well. The HSB color space doesn't suddenly wrap around. It is actually circular. This means that purple (RGB [1, 0, 1]) is at 300° which according to my calculations is the very handy number .8333... in decimal. So one would have to map one interval to another which in this case should be rather simple: just multiply the value by .8333.


\pgfmathtruncatemacro\mymixture{min(100,max(0,##1*100))}\pgfmathparse{min(100,max(0,abs(##1-.5)*100+50))}\edef\x{\noexpand\cellcolor{green!\mymixture!red!\pgfmathresult!yellow!80!gray!\pgfmathresult!white}}\x##1. The solution Christian just proposed might make this a bit more legible. – Christian Nov 23 '12 at 10:25