The first thing to consider when using color to represent data is whether you data are categorical or continuous. The three perceptual dimensions of color, hue, saturation and luminance, process information differently. Hue is great for categorical data. The colors of the rainbow are great to use, but if you want more categories, try more desaturated colors (e.g., salmon, teal, amythyst) instead of saturated spectral colors. You can order categories if your data are ordinal. You can, for example, have a set of colors that are ordered, and that ordering can follow the spectrum.
If the data are continuous (or “quantitative”), then your goal is to convey magnitude. For this, luminance variation is your best bet. Your lowest value should map onto a very dark color and your highest value should map onto a very bright color. This colors however do not have to be just black and white. You can map from a very dark red through orange, to yellow and then white, for example. Just be careful to have perceived luminance increase monotonically, and have smooth transitions between hues. If you want to also show that there are different semantic “bands” in your data, you can quantize the color scale into uniform bins or you can select bins of different sizes and hues to provide that extra dimension. The rainbow colormap is not good for this purpose because luminance is not monotonic and the color bands are not uniformly spaced, which breaks the perception of monotonicity in the data and draws attention to accidental regions in the data.
You can combine these ideas. For example, if you want to represent data that are monotonically increasing above a zero and monotonically decreasing (that is, continuous) below zero, you can use one hue or hue range above zero and a different hue or hue range below zero. This could be a divergent scale, where colors become more saturated and lower luminance the greater the distance from the zero. Or you can have a monotonic luminance scale which just switches hue above zero, as in a topological map.
So, the first step is to understand the structure of your data, then, what aspect are you trying to represent, and then use the three perceptual dimensions of color to guide your selections.