I want to use the jet color function in Mathematica, and the jet color function is defined as


which is from the question: Custom ColorFunction/ColorData in ArrayPlot (and similar functions)

When I use jet to plot, I found that Mathematica will automatically use the maximum and minimum as the data range, there are solutions to rescale the colordata for the default colormap in Mathematica, but I can't use these methods to set the range for jet colormap. Here is a minimum example: The default colormap's range could be set as

DensityPlot[Sin[x]*Cos[y], {x, -1, 1}, {y, -1, 1}, 
 ColorFunction -> (ColorData["TemperatureMap", 
     Rescale[#, {-1, 1}]] &), ColorFunctionScaling -> False, 
 PlotLegends -> BarLegend[{Automatic, {-1, 1}}]]

enter image description here

and if I use jet colorfunction

DensityPlot[Sin[x]*Cos[y], {x, -1, 1}, {y, -1, 1}, 
 ColorFunction -> jet, ColorFunctionScaling -> False, 
 PlotLegends -> BarLegend[{Automatic, {-1, 1}}]]

the data range is not correct enter image description here

  • $\begingroup$ ColorFunctionScaling -> True ? $\endgroup$
    – Syed
    Jun 6, 2022 at 7:37
  • $\begingroup$ This can only change the data range for the barlegend but the density plot range will not chang $\endgroup$
    – Knife Lee
    Jun 6, 2022 at 7:49
  • 1
    $\begingroup$ You already knew what to do in your first snippet; making the replacement with my jet[] function should have been straightforward: DensityPlot[Sin[x]*Cos[y], {x, -1, 1}, {y, -1, 1}, ColorFunction -> (jet[Rescale[#, {-1, 1}]] &), ColorFunctionScaling -> False, PlotLegends -> BarLegend[{Automatic, {-1, 1}}]] $\endgroup$ Jun 6, 2022 at 15:34

1 Answer 1


I found the answer by myself after rereading the other questions:

DensityPlot[Sin[x]*Cos[y]*0.3, {x, -1, 1}, {y, -1, 1}, 
 ColorFunction -> (jet[Rescale[#, {-3, 3}]] &), 
 ColorFunctionScaling -> False, 
 PlotLegends -> BarLegend[{Automatic, {-3, 3}}]]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.