I have a function, say f[x,y] that can return only 3 values: +1, 0, and -1 (it is similar to Sign, but comes from stability analysis of a control system with 2 state variables) I would like to use DensityPlot so that +1, 0 and -1 map to red, white and blue, respectively, over a specified (x,y) plot region Question: how do I set ColorFunction to achieve that mapping? The plot statement is simply
That is what is happening in my posted example. Look at the ColorFunction Documentation under details. It shows. a list of what is sent to the color function for each plotting command. For DensityPlot it sends “f”, the function value, which in your case is “f[x,y]”.
To use it, you make a function that takes that argument (in this case f[x,y]) and returns a color based on that value. Since DensityPlot does not send the x and y values to the color function and only f[x,y] you can only reference the function value as the sole argument of the color function. In my example, I probably confused you by calling that argument “x”. The “x” in the color function is NOT the x coordinate, but rather “f[x,y]”. I should have posted this as my colorfunction to make it easier to understand.