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.

  • $\begingroup$ I guess you are looking for something like this Coloring a shape according to a function. $\endgroup$ – Artes Aug 14 '14 at 16:49
  • $\begingroup$ Yes. I think that will work. RegionPlot looks like the solution. Mebbe I should delete this question. $\endgroup$ – amcalde Aug 14 '14 at 16:51
  • $\begingroup$ 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. $\endgroup$ – amcalde Aug 14 '14 at 18:35
  • 1
    $\begingroup$ Add ColorFunctionScaling->False to your plot and see if that does what you'd like. $\endgroup$ – bobthechemist Aug 14 '14 at 19:33
  • $\begingroup$ That did it, thaks @bobthechemist! $\endgroup$ – amcalde Aug 14 '14 at 19:35

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


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