0
$\begingroup$

I would like to rescale the colors in a plot and to do this in the same way for the color bar. (So this enables me to have the color bar span a (z) range larger than than the data itself.)

I got this running for Plot3D:

Plot3D[Sin[x^2 + y], {x, 0, Pi}, {y, 0, Pi}, 
  ColorFunctionScaling -> False, 
  ColorFunction -> (ColorData["SolarColors", Rescale[#3, {0, 1}, {0, 1}]] &), 
  PlotLegends -> BarLegend[{"SolarColors", {0, 1}}, 10]]

How can I accomplish the same for ListDensityPlot? A simple copy and past doesn't do the job; I get an error w.r.t. the used slot number (#3) in the code above. Which slot should be used for this purpose in ListDensityPlot?

enter image description here enter image description here

$\endgroup$
0
1
$\begingroup$
DensityPlot[Sin[x^2 + y], {x, 0, Pi}, {y, 0, Pi}, 
 ColorFunction -> (ColorData["TemperatureMap", Rescale[#, {0, 2}, {0, 1}]] &), 
 PlotLegends -> BarLegend[{"TemperatureMap", {0, 2}}, 10]]

Mathematica graphics

$\endgroup$
0
$\begingroup$

I modified the answer by belisarius for listdensityplot and moreover I rescaled the barlegend such that the desired result was obtained:

All the data outside the desired range gets the same "bottom" color.

 data = Table[Sin[u + v^2], {u, 0, 3, .05}, {v, 0, 3, .05}];
 zrange = {.5, 1.0}

 ListDensityPlot[data, 
 ColorFunction -> ColorData[{"SolarColors", zrange}], 
PlotLegends -> 
 BarLegend[{(ColorData["SolarColors", Rescale[#, zrange, {0, 1}]] &),
 zrange}]]

enter image description here

The documentation of Mathematica needs an update for this.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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