# Force fixed colormap range for DensityPlot with custom Colormap

I have an issue with the automatic scaling of colors in DensityPlots when i use my imported Jet colormap from Matlab (followed this answer).

I want to keep red (highest value in colormap) always to be connected to 1 and blue (lowest value in colormap) always to be -1. My code looks like this:

cMapJet = Transpose@Import["jet.mat"];
JET = Function[Blend[RGBColor @@@ cMapJet, Slot[1]]];


and a minimized example:

A = 0.5;
DensityPlot[A*Sin[x] /. y -> 0, {z, -1, 1}, {x, -1, 1},
ColorFunction -> JET, PlotRange -> All, PlotLegends -> Automatic]

A2 = 1;
DensityPlot[A2*Sin[x] /. y -> 0, {z, -1, 1}, {x, -1, 1},
ColorFunction -> JET, PlotRange -> All, PlotLegends -> Automatic]


In this question the answer of MicheleG comes very very close to what I want. But I'm not able to implement it in my code.

The cMapJet contains this numbers:

{{{0., 0., 0.515625}}, {{0., 0., 0.53125}}, {{0., 0.,
0.546875}}, {{0., 0., 0.5625}}, {{0., 0., 0.578125}}, {{0., 0.,
0.59375}}, {{0., 0., 0.609375}}, {{0., 0., 0.625}}, {{0., 0.,
0.640625}}, {{0., 0., 0.65625}}, {{0., 0., 0.671875}}, {{0., 0.,
0.6875}}, {{0., 0., 0.703125}}, {{0., 0., 0.71875}}, {{0., 0.,
0.734375}}, {{0., 0., 0.75}}, {{0., 0., 0.765625}}, {{0., 0.,
0.78125}}, {{0., 0., 0.796875}}, {{0., 0., 0.8125}}, {{0., 0.,
0.828125}}, {{0., 0., 0.84375}}, {{0., 0., 0.859375}}, {{0., 0.,
0.875}}, {{0., 0., 0.890625}}, {{0., 0., 0.90625}}, {{0., 0.,
0.921875}}, {{0., 0., 0.9375}}, {{0., 0., 0.953125}}, {{0., 0.,
0.96875}}, {{0., 0., 0.984375}}, {{0., 0., 1.}}, {{0., 0.015625,
1.}}, {{0., 0.03125, 1.}}, {{0., 0.046875, 1.}}, {{0., 0.0625,
1.}}, {{0., 0.078125, 1.}}, {{0., 0.09375, 1.}}, {{0., 0.109375,
1.}}, {{0., 0.125, 1.}}, {{0., 0.140625, 1.}}, {{0., 0.15625,
1.}}, {{0., 0.171875, 1.}}, {{0., 0.1875, 1.}}, {{0., 0.203125,
1.}}, {{0., 0.21875, 1.}}, {{0., 0.234375, 1.}}, {{0., 0.25,
1.}}, {{0., 0.265625, 1.}}, {{0., 0.28125, 1.}}, {{0., 0.296875,
1.}}, {{0., 0.3125, 1.}}, {{0., 0.328125, 1.}}, {{0., 0.34375,
1.}}, {{0., 0.359375, 1.}}, {{0., 0.375, 1.}}, {{0., 0.390625,
1.}}, {{0., 0.40625, 1.}}, {{0., 0.421875, 1.}}, {{0., 0.4375,
1.}}, {{0., 0.453125, 1.}}, {{0., 0.46875, 1.}}, {{0., 0.484375,
1.}}, {{0., 0.5, 1.}}, {{0., 0.515625, 1.}}, {{0., 0.53125,
1.}}, {{0., 0.546875, 1.}}, {{0., 0.5625, 1.}}, {{0., 0.578125,
1.}}, {{0., 0.59375, 1.}}, {{0., 0.609375, 1.}}, {{0., 0.625,
1.}}, {{0., 0.640625, 1.}}, {{0., 0.65625, 1.}}, {{0., 0.671875,
1.}}, {{0., 0.6875, 1.}}, {{0., 0.703125, 1.}}, {{0., 0.71875,
1.}}, {{0., 0.734375, 1.}}, {{0., 0.75, 1.}}, {{0., 0.765625,
1.}}, {{0., 0.78125, 1.}}, {{0., 0.796875, 1.}}, {{0., 0.8125,
1.}}, {{0., 0.828125, 1.}}, {{0., 0.84375, 1.}}, {{0., 0.859375,
1.}}, {{0., 0.875, 1.}}, {{0., 0.890625, 1.}}, {{0., 0.90625,
1.}}, {{0., 0.921875, 1.}}, {{0., 0.9375, 1.}}, {{0., 0.953125,
1.}}, {{0., 0.96875, 1.}}, {{0., 0.984375, 1.}}, {{0., 1.,
1.}}, {{0.015625, 1., 0.984375}}, {{0.03125, 1.,
0.96875}}, {{0.046875, 1., 0.953125}}, {{0.0625, 1.,
0.9375}}, {{0.078125, 1., 0.921875}}, {{0.09375, 1.,
0.90625}}, {{0.109375, 1., 0.890625}}, {{0.125, 1.,
0.875}}, {{0.140625, 1., 0.859375}}, {{0.15625, 1.,
0.84375}}, {{0.171875, 1., 0.828125}}, {{0.1875, 1.,
0.8125}}, {{0.203125, 1., 0.796875}}, {{0.21875, 1.,
0.78125}}, {{0.234375, 1., 0.765625}}, {{0.25, 1.,
0.75}}, {{0.265625, 1., 0.734375}}, {{0.28125, 1.,
0.71875}}, {{0.296875, 1., 0.703125}}, {{0.3125, 1.,
0.6875}}, {{0.328125, 1., 0.671875}}, {{0.34375, 1.,
0.65625}}, {{0.359375, 1., 0.640625}}, {{0.375, 1.,
0.625}}, {{0.390625, 1., 0.609375}}, {{0.40625, 1.,
0.59375}}, {{0.421875, 1., 0.578125}}, {{0.4375, 1.,
0.5625}}, {{0.453125, 1., 0.546875}}, {{0.46875, 1.,
0.53125}}, {{0.484375, 1., 0.515625}}, {{0.5, 1.,
0.5}}, {{0.515625, 1., 0.484375}}, {{0.53125, 1.,
0.46875}}, {{0.546875, 1., 0.453125}}, {{0.5625, 1.,
0.4375}}, {{0.578125, 1., 0.421875}}, {{0.59375, 1.,
0.40625}}, {{0.609375, 1., 0.390625}}, {{0.625, 1.,
0.375}}, {{0.640625, 1., 0.359375}}, {{0.65625, 1.,
0.34375}}, {{0.671875, 1., 0.328125}}, {{0.6875, 1.,
0.3125}}, {{0.703125, 1., 0.296875}}, {{0.71875, 1.,
0.28125}}, {{0.734375, 1., 0.265625}}, {{0.75, 1.,
0.25}}, {{0.765625, 1., 0.234375}}, {{0.78125, 1.,
0.21875}}, {{0.796875, 1., 0.203125}}, {{0.8125, 1.,
0.1875}}, {{0.828125, 1., 0.171875}}, {{0.84375, 1.,
0.15625}}, {{0.859375, 1., 0.140625}}, {{0.875, 1.,
0.125}}, {{0.890625, 1., 0.109375}}, {{0.90625, 1.,
0.09375}}, {{0.921875, 1., 0.078125}}, {{0.9375, 1.,
0.0625}}, {{0.953125, 1., 0.046875}}, {{0.96875, 1.,
0.03125}}, {{0.984375, 1., 0.015625}}, {{1., 1., 0.}}, {{1.,
0.984375, 0.}}, {{1., 0.96875, 0.}}, {{1., 0.953125, 0.}}, {{1.,
0.9375, 0.}}, {{1., 0.921875, 0.}}, {{1., 0.90625, 0.}}, {{1.,
0.890625, 0.}}, {{1., 0.875, 0.}}, {{1., 0.859375, 0.}}, {{1.,
0.84375, 0.}}, {{1., 0.828125, 0.}}, {{1., 0.8125, 0.}}, {{1.,
0.796875, 0.}}, {{1., 0.78125, 0.}}, {{1., 0.765625, 0.}}, {{1.,
0.75, 0.}}, {{1., 0.734375, 0.}}, {{1., 0.71875, 0.}}, {{1.,
0.703125, 0.}}, {{1., 0.6875, 0.}}, {{1., 0.671875, 0.}}, {{1.,
0.65625, 0.}}, {{1., 0.640625, 0.}}, {{1., 0.625, 0.}}, {{1.,
0.609375, 0.}}, {{1., 0.59375, 0.}}, {{1., 0.578125, 0.}}, {{1.,
0.5625, 0.}}, {{1., 0.546875, 0.}}, {{1., 0.53125, 0.}}, {{1.,
0.515625, 0.}}, {{1., 0.5, 0.}}, {{1., 0.484375, 0.}}, {{1.,
0.46875, 0.}}, {{1., 0.453125, 0.}}, {{1., 0.4375, 0.}}, {{1.,
0.421875, 0.}}, {{1., 0.40625, 0.}}, {{1., 0.390625, 0.}}, {{1.,
0.375, 0.}}, {{1., 0.359375, 0.}}, {{1., 0.34375, 0.}}, {{1.,
0.328125, 0.}}, {{1., 0.3125, 0.}}, {{1., 0.296875, 0.}}, {{1.,
0.28125, 0.}}, {{1., 0.265625, 0.}}, {{1., 0.25, 0.}}, {{1.,
0.234375, 0.}}, {{1., 0.21875, 0.}}, {{1., 0.203125, 0.}}, {{1.,
0.1875, 0.}}, {{1., 0.171875, 0.}}, {{1., 0.15625, 0.}}, {{1.,
0.140625, 0.}}, {{1., 0.125, 0.}}, {{1., 0.109375, 0.}}, {{1.,
0.09375, 0.}}, {{1., 0.078125, 0.}}, {{1., 0.0625, 0.}}, {{1.,
0.046875, 0.}}, {{1., 0.03125, 0.}}, {{1., 0.015625, 0.}}, {{1.,
0., 0.}}, {{0.984375, 0., 0.}}, {{0.96875, 0., 0.}}, {{0.953125,
0., 0.}}, {{0.9375, 0., 0.}}, {{0.921875, 0., 0.}}, {{0.90625, 0.,
0.}}, {{0.890625, 0., 0.}}, {{0.875, 0., 0.}}, {{0.859375, 0.,
0.}}, {{0.84375, 0., 0.}}, {{0.828125, 0., 0.}}, {{0.8125, 0.,
0.}}, {{0.796875, 0., 0.}}, {{0.78125, 0., 0.}}, {{0.765625, 0.,
0.}}, {{0.75, 0., 0.}}, {{0.734375, 0., 0.}}, {{0.71875, 0.,
0.}}, {{0.703125, 0., 0.}}, {{0.6875, 0., 0.}}, {{0.671875, 0.,
0.}}, {{0.65625, 0., 0.}}, {{0.640625, 0., 0.}}, {{0.625, 0.,
0.}}, {{0.609375, 0., 0.}}, {{0.59375, 0., 0.}}, {{0.578125, 0.,
0.}}, {{0.5625, 0., 0.}}, {{0.546875, 0., 0.}}, {{0.53125, 0.,
0.}}, {{0.515625, 0., 0.}}, {{0.5, 0., 0.}}}

• Your use case may require that you use Jet, but if you are not required to use Jet, I would recommend using a different colormap. Modern versions of Matlab, matplotlib, and GNUplot default to variations on a blue-green-yellow (Viridis/parula) or purple-orange-white (plasma/afmhot) scale. These maps are linear and have darker colours at one end and lighter at the other. If you're considering publishing, these colormaps are considered better for all readers, but especially those with various kinds of colorblindness. bids.berkeley.edu/resources/videos/… Jun 11, 2020 at 22:20

When ColorFunctionScaling is true, which it is by default, for the plotting function that you're using, then all function values passed to the color function will be rescaled so that the largest value in the plot is 1 and the smallest value is 0. Your color function is made for this case; its lowest value red corresponds to 0 and its highest value blue corresponds to 1. But we can fix that by rescaling the argument being passed to it, so that the value seen by the JET color function defined in your question runs from 0 to 1 when passed a value between -1 and 1.
JET = Function[Blend[