Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

Suppose p is a some point in the plane. The function f[q] defined as

f[q_]:= Block[{d = Norm[p-q]}, RGBColor[1 - d/(1 + d), 0, d/(1 + d)]]

Continuously colors points in the plane by thier distance from p. What is the easiest way to plot this in 2D? I tried DensityPlot but that's not exactly what I'm looking for. Basically I want to specify some color function for points in the plane and plot it. Contours would be a bonus.

Apologies if this exact question has been asked before.

share|improve this question

marked as duplicate by Öskå, Artes, Sjoerd C. de Vries, RunnyKine, Mr.Wizard Aug 14 '14 at 21:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

I guess you are looking for something like this Coloring a shape according to a function. – Artes Aug 14 '14 at 16:49
Yes. I think that will work. RegionPlot looks like the solution. Mebbe I should delete this question. – amcalde Aug 14 '14 at 16:51
OK I can't get this to work for a simple example. I put p = {2,3}, f as above, then RegionPlot[True, {x, 1, 4}, {y, 1, 4}, ColorFunction -> Function[{x, y}, f@{x, y}]] Doesn't work, gives a solid square. – amcalde Aug 14 '14 at 18:35
Add ColorFunctionScaling->False to your plot and see if that does what you'd like. – bobthechemist Aug 14 '14 at 19:33
That did it, thaks @bobthechemist! – amcalde Aug 14 '14 at 19:35
up vote 6 down vote accepted

Just for fun, try this

 RegionPlot[True, {x, 1, 4}, {y, 1, 4}, ColorFunctionScaling -> False,
   ColorFunction -> 
   Function[{x, y}, 
    Block[{d = Norm[l - #]}, 
       RGBColor[1 - d/(1 + d), 0, d/(1 + d)]] & @{x, y}]], {{l, {2, 
    2}}, Locator, Appearance -> None}]

enter image description here

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.