1
$\begingroup$

I want to plot a scalar-field $f(x,y) = \frac{sin(x^2+y^2)}{x^2+y^2}$ and it's gradient-field $\nabla f(x,y)$ in one graphic. Something like "StreamDensityPlot" in 3D. The mesh-lines on the scalar-field should look like arrows which are showing in the direction of the gradient. Thanks very much :)

$\endgroup$
4
$\begingroup$

Expanding on rewi's answer if you want the 3D result:

    f[x_, y_] := Sin[x^2 + y^2]/(x^2 + y^2)

    sdp =
     StreamDensityPlot[  Evaluate[{Grad[f[x, y], {x, y}], f[x, y]}], {x, -3,3}, {y, -3, 3},  PlotRangePadding -> 0, Frame -> False]

enter image description here

    Plot3D[f[x, y], {x, -3, 3}, {y, -3, 3}, PlotRange -> All, PlotStyle -> Texture[sdp], Mesh -> None]

enter image description here

Edit: Is there a bug with using StreamStyle with Texture?

    sdp = StreamDensityPlot[
      Evaluate[{Grad[f[x, y], {x, y}], f[x, y]}], {x, -3, 3}, {y, -3, 3}, 
      PlotRangePadding -> 0, Frame -> False, 
      ColorFunction -> "SolarColors",
      StreamStyle -> White
    ]

enter image description here

The styling isn't carried over:?

    Plot3D[f[x, y], {x, -3, 3}, {y, -3, 3}, PlotRange -> All, 
     PlotStyle -> Texture[sdp], Mesh -> None]

enter image description here

But if we use StreamColorFunction:

    sdp = StreamDensityPlot[
      Evaluate[{Grad[f[x, y], {x, y}], f[x, y]}], {x, -3, 3}, {y, -3, 3}, 
      PlotRangePadding -> 0, Frame -> False, 
      ColorFunction -> "SolarColors",
      StreamColorFunction -> (GrayLevel[1] &)
    ]

enter image description here

    Plot3D[f[x, y], {x, -3, 3}, {y, -3, 3}, PlotRange -> All, 
     PlotStyle -> Texture[sdp], Mesh -> None]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you very much :) How can I change the colour of the scalarfield and the arrows ? $\endgroup$ – astronerd Feb 28 '16 at 11:36
  • $\begingroup$ If you look up StreamDensityPlot you'll find many options and examples of changing the various colors and stylings. You have to change them in the StreamDensityPlot, not the Plot3D as the former is used as a texture map for the later. I'll add an example to my answer. $\endgroup$ – Quantum_Oli Feb 28 '16 at 11:40
1
$\begingroup$

Is this what you are looking for?

f = Sin[x^2 + y^2]/(x^2 + y^2);
StreamDensityPlot[Evaluate[{Grad[f, {x, y}], f}], {x, -5, 5}, {y, -5, 5}]

enter image description here

$\endgroup$
  • $\begingroup$ I want exactly this in 3D :) $\endgroup$ – astronerd Feb 28 '16 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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