I am trying to insert a density plot on a parametric plot in 3D, but I am not successful. I post the part of the code on which I am working on.

b2[r_] := r/Exp[r - r0];
z2[r_] := NIntegrate[(t/b2[t] - 1)^(-1/2), {t, 1, r}];
up2 = ParametricPlot3D[{r*Cos[x], r*Sin[x], z2[r]}, {x, 0, 2 Pi}, {r, 
    1, 10}, ColorFunction -> "LakeColors", 
   PlotStyle -> {"LakeColors", Opacity[0.4]}, PlotPoints -> 50];
dp2 = ParametricPlot3D[{r*Cos[x], r*Sin[x], -z2[r]}, {x, 0, 2 Pi}, {r,
     1, 10}, ColorFunction -> "LakeColors", 
   PlotStyle -> {"LakeColors", Opacity[0.4]}, PlotPoints -> 50];
Show[up2, dp2, PlotRange -> All, Boxed -> False, 
 Axes -> {False, False, False}, 
 ImageSize -> 800]

This is the parametric 3D plot. And I would like to plot on it the following function

\[CapitalPhi2][r_] := -a/r;

I would like to obtain something similar to this image PlotImage. Could you please help me to fix this issue? Thank you very much! :-)

  • $\begingroup$ You are trying to combine a 2D plot with a 3D one. What exactly would you like as the result? $\endgroup$ – MarcoB Jun 10 '20 at 20:09
  • $\begingroup$ Since the figure is axially symmetric, I reduced my density Plot to a 2D function. I would like to plot such function on the ParametricPlot3D. This is a simple case where my density function is a constant, but I guess that once this is issue is fixed, the general case can be easily extended. Thanks! $\endgroup$ – VDF Jun 10 '20 at 20:13
  • $\begingroup$ I'm sorry, that's still not very clear. Here is something that reproduces the image you included, at least as a concept. See if you can use that as an example of what you woudl like to achieve. ContourPlot3D[z^2 - x^2 + y^2 == 2, {x, -4, 4}, {y, -4, 4}, {z, -4, 4}, ColorFunction -> (ColorData["TemperatureMap"][#1] &)] $\endgroup$ – MarcoB Jun 10 '20 at 21:20
  • 1
    $\begingroup$ Thank you very much for your help. However it is not what I would like to do. Sorry if I was not clear. I will try to explain clearer my problem: I have a parametric 3D plot and on this plot I would like to add a density plot. $\endgroup$ – VDF Jun 10 '20 at 21:26

The ColorFunction option of ParametricPlot3D can color the surface according to a function you specify. Here's a simpler example to show the idea without the NIntegrate.

The function you'd like to use as a density plot on the parametric plot has a typo: \[CapitalPhi]2 instead of \[CapitalPhi2]. You don't specify a value for the parameter a, so I set a=1 for this example:

\[CapitalPhi]2[r_] := -1/r;

The ColorFunction option of ParametricPlot3D has r as its fifth argument. You need to scale the range of the function to the range 0 to 1 for color gradients, e.g., using Rescale:

With[{rMin = 1, rMax = 10},
  ParametricPlot3D[{r*Cos[x], r*Sin[x], r}, {x, 0, 2 Pi}, {r, rMin, rMax}, 
    ColorFunction -> (ColorData["TemperatureMap"][
      Rescale[\[CapitalPhi]2[#5], {\[CapitalPhi]2[rMin], \[CapitalPhi]2[
     rMax]}]] &), 
    ColorFunctionScaling -> False]

density plot coloring a 3D parametric plot

  • $\begingroup$ Thank you very much @tad, this indeed a very good and simple solution that I have adapted to my case. Last question, if I would like to insert also the BarLegend, how I should do? Thank you again for your great help! $\endgroup$ – VDF Jun 10 '20 at 23:34
  • $\begingroup$ You could make the legend manually, e.g., BarLegend[{"TemperatureMap", {-1, -1/10}}] and combine with the plot using Legended. $\endgroup$ – tad Jun 10 '20 at 23:55
  • $\begingroup$ Thank you very much! $\endgroup$ – VDF Jun 11 '20 at 0:09

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.