# Density Plot on a Parametric Plot 3D

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! :-)

• You are trying to combine a 2D plot with a 3D one. What exactly would you like as the result? Jun 10, 2020 at 20:09
• 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!
– VDF
Jun 10, 2020 at 20:13
• 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] &)] Jun 10, 2020 at 21:20
• 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.
– VDF
Jun 10, 2020 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]
]


• 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!
– VDF
Jun 10, 2020 at 23:34
• You could make the legend manually, e.g., BarLegend[{"TemperatureMap", {-1, -1/10}}] and combine with the plot using Legended.