# can't blend gradient colors with a stream

The following function generates a plot of the 3d function indicated in the example.

Plot3D[(x^2 + y^2) Exp[1 - x^2 - y^2], {x, -3, 3}, {y, -3, 3},
Mesh -> None, ImageSize -> Large, PlotPoints -> 35,
PlotStyle -> {Texture[
StreamPlot[
Evaluate[-D[(x^2 + y^2) Exp[1 - x^2 - y^2], {{x, y}}]], {x, -3,
3}, {y, -3, 3}, Frame -> None, ImageSize -> Large,
StreamStyle -> Black]]}]


However, when I choose a different ColorFunction parameter the texture (that only consists of arrows) disappears. Any idea how to correct this? I tried to make the background transparent, combine two 3D plots etc without success. Also, I have no idea why this is happening.

Here is the 3D plot without the gradient field.

Plot3D[(x^2 + y^2) Exp[1 - x^2 - y^2], {x, -3, 3}, {y, -3, 3},
Mesh -> None, ImageSize -> Large, PlotPoints -> 35,
PlotStyle -> {Texture[
StreamPlot[
Evaluate[-D[(x^2 + y^2) Exp[1 - x^2 - y^2], {{x, y}}]], {x, -3,
3}, {y, -3, 3}, Frame -> None, ImageSize -> Large,
StreamStyle -> Black]]}, ColorFunction -> "Rainbow"]


The color is not quite right but the idea seems to work. Edit: much closer now.

dp = DensityPlot[(x^2 + y^2) Exp[1 - x^2 - y^2], {x, -3, 3}, {y, -3, 3},
ColorFunction -> "Rainbow", PlotPoints -> 100];

sp = StreamPlot[
Evaluate[-D[(x^2 + y^2) Exp[1 - x^2 - y^2], {{x, y}}]], {x, -3, 3}, {y, -3, 3},
Frame -> None, ImageSize -> Large, StreamStyle -> Black];

tex = Show[dp, sp, Frame -> None, PlotRangePadding -> 0, ImageSize -> 500];

Plot3D[(x^2 + y^2) Exp[1 - x^2 - y^2], {x, -3, 3}, {y, -3, 3}, Mesh -> None,
ImageSize -> Large, PlotPoints -> 35
, PlotStyle -> {Texture[Lighter[tex, 0.15]]}
, Lighting -> "Neutral"
] You can use StreamDensityPlot (which accepts the ColorFunction option) to produce the texture:

sdp = StreamDensityPlot[Evaluate[{-D[(x^2 + y^2) Exp[1 - x^2 - y^2], {{x, y}}],
(x^2 + y^2) Exp[1 - x^2 - y^2]}], {x, -3, 3}, {y, -3, 3},
StreamStyle -> Black,
ColorFunction -> "Rainbow",
ColorFunctionScaling -> False, Frame -> False, Axes -> False,
Plot3D[(x^2 + y^2) Exp[1 - x^2 - y^2], {x, -3, 3}, {y, -3, 3},
Mesh -> None, ImageSize -> Large, PlotPoints -> 35,
PlotStyle -> Texture[Lighter@sdp], Lighting -> "Neutral"] • Slightly shorter: sdp = StreamDensityPlot[ Evaluate[{-D[#, {{x, y}}], #} &[(x^2 + y^2) Exp[ 1 - x^2 - y^2]]], {x, -3, 3}, {y, -3, 3}, StreamStyle -> Black, ColorFunction -> "Rainbow", Frame -> False, Axes -> False, PlotRangePadding -> None]; – Michael E2 Jan 14 '19 at 21:55
• @MichaelE2, I tried that version; but the colors do not match the colors in Plot3D. – kglr Jan 14 '19 at 23:01
• Odd, they match your code above, for me. I switched between the two images and saw no (perceptible) difference. – Michael E2 Jan 14 '19 at 23:02
• @MichaelE2, maybe version/os difference (i am using v 11.3 windows 10/64bit). – kglr Jan 14 '19 at 23:04
• @MichaelE2, ColorFunction -> "Rainbow" does work if the first argument of StreamDensityPlot has the form $\{\{v_x, v_y\}, s \}$. – kglr Jan 15 '19 at 1:39

PlotStyle -> Texture[...] relies on VertexTextureCoordinates to map the texture to polygon vertices.

ColorFunction -> colorfunction relies on VertexColors to associate colors with the polygon vertices.

Only one of them actually gets to style the polygon. In my case, it seems to be the texture:

Graphics3D[{Texture[RandomImage[1, 100]],
Polygon[{{0, 0, 0}, {1, 0, 0}, {1, 1, 0}},
VertexColors -> {Red, Green, Blue},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}}]},
Lighting -> "Neutral", BoxRatios -> {1, 1, 1}] It sounds like the color function is winning in your case. It wouldn't surprise me if that was dependent on things like OS, software version, phase of the moon, etc...