Dynamic (or forced) scaling of ColorFunction

Reading this question on importing ColorData from Matlab, I was wondering if there is a way to change the range of values ​​over which the ColorFunction scales. This is probably not entirely clear, so let me show a figure from matlab (using the same example as in the previous question)

enter image description here

The chart on the left is the original, and ColorData mapped to data values ​​between -1 and 1 . Now I can easily configure it to match data values ​​between 0 and 1 , the result of which is that for all values ​​less than 0 , a blue color is assigned (the lowest in the color palette). PlotRange is the closest function, and with the help of ClippingStyle in addition to this we get a similar figure. However, it does not re-scale the ColorData to display the range of the graph.

How can I do this in Mathematica?

BTW, to insert colored panels using Mathematica, you can watch this function

+4
source share
1 answer

Here's the function applied to the surface:

 Plot3D[x + y, {x, -2, 2}, {y, -2, 2}, ColorFunction -> (ColorData["Rainbow", #3] &), Mesh -> {{1}, {1}}] 

To look in the upper right corner, with the same color function and scaling, I set ColorFunctionScaling -> False and manually scaled the color function to match the (global) minimum to zero and the maximum to unity using Rescale

 Plot3D[x + y, {x, 1, 2}, {y, 1, 2}, ColorFunctionScaling -> False, ColorFunction -> (ColorData["Rainbow", Rescale[#3, {-4, 4}, {0, 1}]] &)] 

screenshot of the two plots

+9
source

All Articles