# ColorFunction with the function of luminance

I want to have a DensityPlot or ListDensityPlot, whose color function is a rainbow but whose luminance is given by another function. For example, I've attached an image of a vortex, whose color function shows the phase and its luminance shows the intensity. In the following plot, you can use F1 = ArcTan[x,y] function with luminance F2 = (x^2+y^2)*Exp[-x^2-y^2].

• Could you show the complete code that generated the image you showed? Jul 18, 2016 at 0:05
• You've seen Hue[], right? Jul 18, 2016 at 0:07
• Yes I sow it, but I can use that only for Plot3D (see Below the code). I want the same dependence but for DensityPlot and more for ListDensityPlot. Plot3D[(x^2 + y^2) Exp[-x^2 - y^2], {x, -3, 3}, {y, -3, 3}, PlotPoints -> 50, ColorFunction -> Function[{x, y, z}, Hue[Rescale[ArcTan[x, y], {-Pi, Pi}]]], ColorFunctionScaling -> False, PlotLegends -> Automatic] Jul 18, 2016 at 11:31

Edit

### Table Case

Kuba, can you add also a solution for tables instead of functions, because in fact I have something like this: table1 = Table[(x^2 + y^2) Exp[-x^2 - y^2], {x, -3, 3}, {y, -3, 3}], table2 = Table[ArcTan[x, y], {x, -2.999, 3}, {y, -3., 3}]

– Mushegh

{
table1 = Table[(x^2 + y^2) Exp[-x^2 - y^2], {x, ##}, {y, ##}],
table2 = Table[Arg[x + I y], {x, ##}, {y, ##}]
} & @@ {-3, 3, .2};

Image[
Reverse[#, 2] & @ Transpose @ MapThread[
{(#2 - Pi/2.)/Pi, 1, # E } &,
ArrayResample[#, {500, 500}] & /@ N[{table1, table2}],
2
],
ColorSpace -> "HSB"
]


You have probably noticed a strange "outflow". That is because of the interpolation of positive "x" axis neighborhood for ArcTan[x,y]:

table2 // ListPlot3D


Here is a fix:

res = ArrayResample[N@#, {500, 500}, ##2] &;
Image[
{Which[#3 > 0, ArcSin[#2], #2 > 0, ArcCos[#2] + Pi/2, True,
ArcCos[#2] - 3 Pi/2]/Pi - 1/2., 1, # E} &,
{
res@table1,
res[Sin@table2],
res[Cos@table2]
},
2
],
ColorSpace -> "HSB"
]


### Functions case

plot = ParametricPlot[{x, y}, {x, -#, #}, {y, -#, #},
ColorFunction        -> Function[{x, y, u, v},
Directive[
Opacity[E (x^2 + y^2)*Exp[-x^2 - y^2]], (*E - scaling factor*)
Hue[(ArcTan[x, y] - Pi/2)/Pi]
]
],
PlotPoints           -> 100,
ColorFunctionScaling -> False,
Axes                 -> False,
Frame                -> False,
Background           -> Black,
BoundaryStyle        -> None,
ImageSize            -> {Automatic, 300},
Mesh                 -> None
] &@3

barLegend = ParametricPlot[{x, y}, {x, 0, .1}, {y, 0, 2 Pi},
ColorFunction    -> (Hue[#2] &),
AspectRatio      -> 10,
FrameTicks       -> {{False, {0, 2 Pi}}, {False, False}},
BaseStyle        -> 24,
FrameLabel       -> {{None, "Phase"}, {None, None}},
ImageSize        -> {Automatic, 300},
Mesh             -> None
]

Grid[{{plot, barLegend}}]


• the "BaseStyle" and "Ticks" are not working. Is it problem of Mathematica version I have? it is Mathematica 9.0 Jul 19, 2016 at 12:29
• Also the color bar is discrete colors from orange to red Jul 19, 2016 at 12:38
• @Mushegh I've changed BarLegend so Ticks should be correct now. What do you mean in your second comment?
– Kuba
Jul 19, 2016 at 12:47
• @Mushegh, Hue[0] and Hue[1] are both red. Jul 19, 2016 at 13:01
• Now it is working, I have added "Mesh-> None", because it was bringing some mesh on the plot. Thanks Jul 19, 2016 at 13:54

No legend for this slight simplification of Kuba's proposal, but it can be easily added if desired:

RegionPlot[True, {x, -3, 3}, {y, -3, 3}, Background -> Black, BoundaryStyle -> None,
ColorFunction -> Function[{x, y}, Hue[(Arg[x + I y] - Pi/2)/Pi, 1, 1,
(x^2 + y^2) Exp[1 - x^2 - y^2]]],
ColorFunctionScaling -> False, Frame -> False, PlotPoints -> 95]


• Thank you for short solution, can you add also a solution for tables instead of functions, because in fact I have something like this: table1 = Table[(x^2 + y^2) Exp[-x^2 - y^2], {x, -3, 3}, {y, -3, 3}] table2 = Table[ArcTan[x, y], {x, -2.999, 3}, {y, -3., 3}] Jul 19, 2016 at 23:27
• If I am trying to use interpolation and after your option, the plots are loosing the quality. Jul 19, 2016 at 23:27
• @Mush, why did you not post that problem to begin with?! Jul 19, 2016 at 23:31
• In the begining I thougth that knowing the solution for functions is enough, because I can after interpolate the data to a function, but then I have tried it and sow that the quality is very bad by interpolation option Jul 20, 2016 at 12:57
• Actually I have this option, can you comment to it? Jul 20, 2016 at 12:57