Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
1  
Prepending`Rescale[#, {-1, 1}] & /@` to RGBColor prettifies this nicely. +1 –  rasher Jun 10 at 7:20
    
@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 –  Kuba Jun 10 at 7:25
    
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. –  Bryan Clair Jun 11 at 6:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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