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 is scaled. That was probably not entirely clear, so let me show with a figure from matlab (the same example as in the previous question is used)
The plot on the left is the original, with the ColorData
mapped to the data values between -1
and 1
. Now, I can easily set it to be mapped to the data values between 0
and 1
, the result being that all values less than 0
are assigned blue color (lowest in the colormap). PlotRange
is the closest function, and using ClippingStyle
in addition to th开发者_开发技巧at produces a similar figure. However, it doesn't re-scale the ColorData to map to the plot range.
How can I do this in Mathematica?
BTW, to insert colorbars using Mathematica, you can look at this function
Here's a function applied to a surface:
Plot3D[x + y, {x, -2, 2}, {y, -2, 2},
ColorFunction -> (ColorData["Rainbow", #3] &), Mesh -> {{1}, {1}}]
To look at the top-right corner, with the same color function and scaling, I set ColorFunctionScaling -> False
, and manually scale the color function to map the (global) minimum to zero and the maximum to one using Rescale
:
Plot3D[x + y, {x, 1, 2}, {y, 1, 2}, ColorFunctionScaling -> False,
ColorFunction -> (ColorData["Rainbow", Rescale[#3, {-4, 4}, {0, 1}]] &)]
精彩评论