Message Boards Message Boards

0
|
6264 Views
|
3 Replies
|
4 Total Likes
View groups...
Share
Share this post:

[?]  Color Function not correctly mapping to range?

Posted 6 years ago

Observe the following code:

nd[y_, a_, b_, n_] := (Binomial[b - a + 1, y]*Sum[((-1)^i)*Binomial[y, i]*((y - i)/(b - a + 1))^n, {i, 0, y}]);
mycolorfun = Function[Blend[{Black, Purple, Blue, Green, Yellow, Orange, Red, White}, Rescale[#, {0, 1}]]]
Manipulate[
 ArrayPlot[Table[nd[y, 1, K, n], {K, 1, 25}, {n, 1, 25}], 
  ColorFunction -> mycolorfun, DataReversed -> True, Frame -> True, 
  FrameTicks -> Automatic, 
  FrameLabel -> {Rotate["K", -90 Degree], "N"}], {y, 1, 15, 1}]

Notice how when the slider is moved up to y=15, there is a white square that appears at N = 25 and K = 21:

enter image description here

My goal is for the color function to map the individual value of the output of my function to a color as dependent on its closeness to 0 or 1 (since my function is a probability density function, this makes sense).

However, look what happens when you check the actual value of the function for N = 25 and b=K=21:

nd[15, 1, 21, 25.0]
(out) 0.268495

I get 26%! 26% should be mapping to a color somewhere around Purple/Blue, but it's getting mapped all the way up to the color white! White is what's supposed to be mapped to when the output of my function is really close to 1! Clearly something is amiss here, and I cannot figure out what it is. Can somebody please explain what is going on and what I need to do to get the desired color output?

POSTED BY: John Travolski
3 Replies

This is the normal behavior with 2D plotting functions, the values are rescaled to lie between 0 and 1 before being fed to the color function. If you use the option PlotLegends -> Automatic you can see the color mapping that is being used. Use the option ColorFunctionScaling -> False for your ArrayPlot call to turn off the automatic rescaling.

See http://reference.wolfram.com/language/ref/ColorFunctionScaling.html, or https://mathematica.stackexchange.com/search?q=colorfunctionscaling for more information.

POSTED BY: Jason Biggs
Posted 6 years ago

If I turn off automatic rescaling, then how do I determine which value corresponds to what color?

POSTED BY: John Travolski
Posted 6 years ago

If automatic rescaling is turned off, then the coloring is exactly as given by your ColorFunction. If you say ColorFunction -> myColorFunc, ColorFunctionScaling -> False, then 0.3 should be colored exactly as myColorFunc[ 0.3]. Use PlotLegends -> Automatic to see a color bar.

POSTED BY: Updating Name
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract