I have the following function of five parameters of which I would like to construct a 3D density plot using Plot3D

d = 4 (12 g1^2 + 12 g2^2 + 12 g3^2 - Γ^2 + Γ κ1 - κ1^2 + (Γ + κ1) κ2 - κ2^2)^3 + (36 g1^2 (Γ + κ1 - 2 κ2) + (36 g3^2 - (Γ + κ1 - 2 κ2) (2 Γ - κ1 - κ2)) (Γ - 2 κ1 + κ2) + 36 g2^2 (-2 Γ + κ1 + κ2))^2

I then do

solg3 = g3 /.Solve[d == 0, g3] /. {Γ -> 0.01, κ1 -> 1, κ2 -> 20};

And plot

Plot3D[solg3, {g1, 0, 2.5}, {g2, 0, 8}, ImageSize -> Large, PlotRange -> All, RegionFunction -> Function[{g1, g2, solg3}, solg3 >= 0]]

I am returned with

enter image description here

At this point, I am seeing a lot of jagged lines on the contour and I'm not sure why this is happening. Firstly, it can be seen that there are six solutions to solg3 but I only want positive values of g3 hence there are only three contours. However, I'm puzzled by the appearance of those jagged lines on the lower edges of the contour surface. Why is this happening? And why are there gaps? Is it saying that g3 is complex in those regions?

  • 1
    $\begingroup$ try the option MaxRecursion with a large value (say MaxRecursion -> 10) and increase PlotPoints (say PlotPoints->200) $\endgroup$
    – kglr
    Commented Jun 13, 2019 at 21:09
  • $\begingroup$ If you don't know this, the LeafCount of solg3 is about 2800. peek at the FullForm of your function to see what you are expecting it to precisely plot. Simplify makes it even worse! Is there any way you can simplify that function 50 or 100 fold? PlotPoints->5 makes it less jagged, but I'm expecting that won't be acceptable either. $\endgroup$
    – Bill
    Commented Jun 13, 2019 at 21:26
  • $\begingroup$ @kglr The plot is still simplifying past 20 minutes. I do not think that having MaxRecursion of 10 and PlotPoints of 200 is tractable. Any other ideas? $\endgroup$
    – kowalski
    Commented Jun 13, 2019 at 21:33
  • $\begingroup$ @Bill That is the best I can do in simplifying d. And PlotPoints of 5 is not enough. Any other suggestions? $\endgroup$
    – kowalski
    Commented Jun 13, 2019 at 21:35

1 Answer 1


Looks like a job for ContpurPlot3D:

dd = d /. {Γ -> 0.01, κ1 -> 1, κ2 -> 20};
 dd == 0,
 {g1, 0, 2.5}, {g2, 0, 8}, {g3, 0, 4},
 AxesLabel -> {"g1", "g2", "g3"},
 MaxRecursion -> 5

enter image description here

The result is still a bit jagged (at other places; try also different values of MaxRecursion), but much less.

  • $\begingroup$ Thanks this looks like what I'm looking for! My question is, given that the solution to dd == 0 has 6 solutions, shouldn't I be seeing 6 different contours? Or at least 3 of them since the other 3 is simply the negative of the former. $\endgroup$
    – kowalski
    Commented Jun 14, 2019 at 15:13
  • $\begingroup$ ContourPlot3D employs purely numerical techniques (most likely bisection techniques for root finding). This is why it cannot distinguish the algebraic branches of the solition set. ContourPlot3D does apply different colors for different levelsets, though. $\endgroup$ Commented Jun 14, 2019 at 15:18
  • $\begingroup$ The equations might have six solutions in the complex numbers. Notice however, that (i) we limit the search range by {g1, 0, 2.5}, {g2, 0, 8}, {g3, 0, 4} and that (ii) ContourPlot3D ignores all nonreal solutions. $\endgroup$ Commented Jun 14, 2019 at 15:19
  • $\begingroup$ I will have to look up on applying the colors separately for separate contours on the plot. I would, ideally, match the colors that I obtained from Plot3D but I'm skeptical of the plot regions, especially the jagged ones. $\endgroup$
    – kowalski
    Commented Jun 14, 2019 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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