1
$\begingroup$

I have a vector (3D) valued function of two variables. I want to visualize it as a density plot, using R,G,B color values to display the value at the point (x,y). I've come up with a couple of attempts, neither satisfactory. One is to use a Raster, but that doesn't adapt to the function and so needs too many function evaluations. My other solution is to make three contour plots and combine them, but to do that I needed to use Opacity and then the range of colors is muted.

Here's an example, with a simple function:

f[x_, y_] := {x, y, x + y}
Table[
   DensityPlot[f[x, y][[i]], {x, -1, 1}, {y, -1, 1},
               ColorFunction -> (ReplacePart[RGBColor[0,0,0], i -> #] &)],
   {i, 3}]
Show[Table[
   DensityPlot[f[x, y][[i]], {x, -1, 1}, {y, -1, 1},
         ColorFunction -> ({Opacity[1/3], ReplacePart[RGBColor[0,0,0], i -> #]} &)],
   {i, 3}]]

The first table shows three DensityPlots with the RGB components I want, which look like this:

rgb component images

The Show combines them into one. But what I really want to do is add the color values in the three plots, and Show with Opacity averages them, giving a murky image. In this example, I want white in the upper right, black in the lower left.

$\endgroup$

1 Answer 1

1
$\begingroup$

Is this what you are after?

ParametricPlot[{x, y}, {x, -1, 1}, {y, -1, 1}, Mesh -> None, Frame -> True, Axes -> False,
 ColorFunction -> (RGBColor[#, #2, # + #2] &), ColorFunctionScaling -> False]

enter image description here

or maybe, as Rasher has suggested:

ParametricPlot[{x, y}, {x, -1, 1}, {y, -1, 1}, Mesh -> None, Frame -> True, Axes -> False, 
  ColorFunction -> (Rescale[#, {-1, 1}] & /@ RGBColor[#, #2, # + #2] &),    
  ColorFunctionScaling -> False]

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ PrependingRescale[#, {-1, 1}] & /@ to RGBColor prettifies this nicely. +1 $\endgroup$
    – ciao
    Jun 10, 2014 at 7:20
  • $\begingroup$ @rasher well, I'm not sure what OP wants :) You are probably right, I was thinking about the same but via {x, 0, 1}, {y, 0, 1}, ..., ColorFunction -> (RGBColor[#, #2, (# + #2)/2] & :). Or similar, because it is not the same :P $\endgroup$
    – Kuba
    Jun 10, 2014 at 7:25
  • $\begingroup$ Both of these seem like useful general techniques, and in fact the first one works well for me since the actual function I'm dealing with is already scaled to be in [0,1].For a general function f, the Rescale would need to be a bit fancier to adapt to what might be different ranges for the three coordinates of f. $\endgroup$ Jun 11, 2014 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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