0
$\begingroup$

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

jet[u_?NumericQ]:=Blend[{{0,RGBColor[0,0,9/16]},{1/9,Blue},{23/63,Cyan},{13/21,Yellow},{47/63,Orange},{55/63,Red},{1,RGBColor[1/2,0,0]}},u]/;0<=u<=1

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

$\endgroup$
3
  • $\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

1
$\begingroup$

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

$\endgroup$

Your Answer

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

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