4
$\begingroup$

I have a 3D density plot that I was able to get to look okay with setting ColorFunctionScaling and OpacityFunctionScaling to True. I know that there are other ways to view this data, but I checked the documentation and both these functions treat the minimum value as 0 and the maximum as 1. With the 3D plot, this obscures the middle. Is there a way to have it so that for example, the whole plot is scaled with opacity between 0 and 0.7?

Here is the example I am using. If possible I would also like the color function reduced to between 0 and 1/14.

prob1 = (E^(-2 Im[ArcTan[x, y]] - Re[Sqrt[x^2 + y^2 + z^2]]) Abs[x^2 + y^2])/(64 \[Pi]);

P1 = 
 DensityPlot3D[prob1, {x, -20, 20}, {y, -20, 20}, {z, -20, 20},
  AxesLabel -> {"x", "y", "z"}, ColorFunction -> Hue, 
  OpacityFunction -> Function[a, a^1.2], 
  ColorFunctionScaling -> True, OpacityFunctionScaling -> True,
  FaceGrids -> {{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}}, 
  Ticks -> Table[{{-20,"-20a0"}, {-10,"-10a0"}, {0, "0"}, {10,"10a0"}, {20, "20a0"}}, {i, 3}], 
  PlotLegends -> Automatic]

This yields the above: Density Plot Graph

I'm looking for a way to lower the opacity of the inside of the doughnut in that same kind of exponential function I have, and I want the maximum opacity to be 0.7. The prob1 function just takes to long to run if I add a Maximize. Any suggestions?

$\endgroup$
1
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$ – bbgodfrey Jun 8 at 11:28
5
$\begingroup$

Set

OpacityFunctionScaling -> False

and adjust the OpacityFunction to perform the scaling itself. Since the minimum value of prob1 is 0 and from the legend (produced by DensityPlot3D but not shown in the plot in the question) the maximum is about .0027, the function should read

OpacityFunction -> Function[a, (a/.0027)^1.2]

which indeed reproduces the plot in the question. To reduce the maximum opacity to 0.7 instead of 1, use

OpacityFunction -> Function[a, .7 (a/.0027)^1.2]

This choice does not change the plot much, but reducing the factor from .7 to, for instance .3 produces a very noticeable change.

enter image description here

How much is enough is in the eye of the beholder. Incidentally, the scale factor, .0027, also can be obtained from

prmax = FindMaximum[prob1, {x, y, z}] // First
(* 0.00269241 *)
$\endgroup$

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.