# Plot a function that gives a color [duplicate]

I have a function that takes in two numbers and returns a RGB color. I would like to plot that function on a 2D surface. How can I do that?

• Where is the function? – J. M. will be back soon Oct 25 '15 at 15:57
• – Michael E2 Oct 25 '15 at 15:59
• @J. M. ChromaticityPlot["RGB"]; {x, y, z} = Interpolation[ Thread[{ImageColorOperationsDump\$wavelengths, #}]] & /@ Transpose[ImageColorOperationsDumptris]; , XYZClipped[S_, E_] := NIntegrate[{x[l], y[l], z[l]}, {l, S, E}]/ NIntegrate[x[l] + y[l] + z[l], {l, S, E}]. The function I want to plot is XYZColor[XYZClipped[S,E]] from 400 to 700. – abcd1234 Oct 25 '15 at 15:59
• That returns an XYZ color, not an RGB color. You could probably use Table[] and Image[] for this. – J. M. will be back soon Oct 25 '15 at 16:07

Use RegionPlot with ColorFunction. It is important to use ColorFunctionScaling -> False otherwise your function will be given modified x and y values.

RegionPlot[
True, {x, -1, 1}, {y, -1, 1},
ColorFunction -> Function[{x, y}, GrayLevel@Norm[{x, y}]],
ColorFunctionScaling -> False,
BoundaryStyle -> None
] If your color function is a linear interpolation based on some "sources" you can use VertexColors. The example from the documentation is

Graphics[Polygon[{{-1, 0}, {1, 0}, {0, Sqrt}}, VertexColors -> {Red, Green, Blue}]] And of course you can also sample your points and create an image manually. For example

pixels = Table[
GrayLevel@Norm[{x, y}],
{x, -1, 1, 0.01}, {y, -1, 1, 0.01}
];
Image[pixels] 