Use selfdefined ColorFunction to encode z dimension with predefined limits

In my last question we defined a colorfunction cf. Now I want to use this ColorFunction for a number of different plots (MatrixPlot, BarChart3D, ListContourPlot and ListPlot3D) as encoding for the z value from a given table. For the ListContourPlot and BarChart3D it seems to work, but I don’t know how to apply the color encoding for the remaining plots.

An another problem is the definition of a interval for the color encoding – here I mean that my data ranges from e.g. 0…30 , but i want to define a limit for the ColorFunction such that values are encoded from 10…20 according to the ColorFunction, values below 10 and over 30 should be clamped to the extrema of the ColorFunction. Is it possible to achieve something like that?!

Thanks in advance!

dataResponse = {{1, 1, 3.}, {2, 1, 3.5}, {3, 1, 5.5}, {4, 1, 9.}, {5, 1, 13.}, {6, 1,
30.}, {1, 2, 3.5}, {2, 2, 5.5}, {3, 2, 7.5}, {4, 2, 8.5}, {5, 2,
15.}, {6, 2, 30.}, {1, 3, 4.}, {2, 3, 5.5}, {3, 3, 8.5}, {4, 3,
10.}, {5, 3, 20.5}, {6, 3, 30.}, {1, 4, 4.5}, {2, 4, 7.5}, {3, 4,
12.5}, {4, 4, 30.}, {5, 4, 30.}, {6, 4, 30.}, {1, 5, 5.}, {2, 5,
8.}, {3, 5, 14.5}, {4, 5, 30.}, {5, 5, 30.}, {6, 5, 30.}, {1, 6,
7.5}, {2, 6, 13.}, {3, 6, 30.}, {4, 6, 30.}, {5, 6, 30.}, {6, 6,
30.}}

cbData = {{215, 48, 39},{252, 141, 89},{254, 224, 144}, {224, 243, 248}, {145, 191, 219}, {69, 117, 180}}
cbData = Reverse[cbData]
With[{rgb = RGBColor @@@(cbData/255)},
cf = Blend[rgb, #]&;
]

ListPlot3D[ dataResponse,
Mesh -> All,
ColorFunction -> cf,
Boxed -> False,
FaceGrids -> {
{Bottom,{Range[0,5,1],Range[0,5,1]}},
{Back,{Range[0,5,1],Range[0,30,5]}},
{Left,{Range[0,5,1],Range[0,30,5]}}},
AspectRatio->1,
AxesLabel -> {“Scene Complexity”,”Object Coherence”,”Response Time”},
Ticks -> { {{0,20},{1,30},{2,40},{3,50},{4,60},{5,70}}, {{0,0.045},{1,0.054},{2,0.063},{3,0.072},{4,0.081},{5,0.09}} ,Range[0,30,5]}
]

As you can see the resulting mesh is color-coded along the y axis, but I want to have the z-axis color encoded and in addition the values from 0…10 should have the same blue and values 20…30 should be red –> so that they are clamped

=================

  

 

What didn’t work when you tried using it with ListContourPlot or MatrixPlot? Please add an example (code) of what you want to do (and what you’ve tried). From a cursory reading, this looks like something that’s adequately covered by the docs on ColorFunction and other questions here on the topic.
– R. M.♦
Nov 16 ’12 at 17:04

  

 

Could you give an example of what output you want? Rescale is usually helpful when scaling/translating values
– ssch
Nov 16 ’12 at 17:06

  

 

I already mentioned Rescale[] in the other post, but it seems to have not been heeded…
– J. M.♦
Nov 16 ’12 at 17:09

=================

1 Answer
1

=================

Start by reading the documentation pages for ColorFunctionScaling and Rescale.

Then observe this use:

cf = ColorData[“TemperatureMap”];

ArrayPlot[{Range@40},
ColorFunction -> (cf@Rescale[#, {20, 30}] &),
ColorFunctionScaling -> False,
FrameTicks -> True
]

After understanding this if you still have trouble applying it to a certain plot please ask a specific question including what you have tried.

I see from your example that there is another major aspect to your question: the z scale. Please see the documentation for ColorFunction to see how colors for each axis are defined. Here is an example:

ListPlot3D[
Table[Sin[j^2 + i] + Mod[i, 6], {i, 0, Pi, Pi/5}, {j, 0, Pi, Pi/5}],
Mesh -> None,
ColorFunctionScaling -> False,
InterpolationOrder -> 0,
ColorFunction -> (cf @ Rescale[#3, {2, 3}] &)
]

Pay very close attention to #3 and be sure to read Slot and Function carefully.

  

 

+1 Best answer possible!
– ssch
Nov 16 ’12 at 18:26