3
$\begingroup$

I am plotting the same function using ListDensityPlot and DensityPlot but the output is different!
There are some points where the function is complex or pure imaginary where DensityPlotshow this region as White. However, ListDensityPlot show coloring in the same region.

mod = ParallelTable[
   With[{κ = 0.23}, {ky, ϵ, 
     Sqrt[-ky^2 + ϵ^2 + κ^2 - 
      Sqrt[ϵ^2 - 4 ky^2 κ^2 + 
       4 ϵ^2 κ^2]]}], {ky, -0.35, 0.35, 
    0.001}, {ϵ, 0, 0.2, 0.001}];
ListDensityPlot[Flatten[mod, 1]]  

enter image description here

With[{κ = 0.23}, 
 DensityPlot[
  Sqrt[-ky^2 + ϵ^2 + κ^2 - 
   Sqrt[ϵ^2 - 4 ky^2 κ^2 + 
    4 ϵ^2 κ^2]], {ky, -0.35, 0.35}, {ϵ, 
   0, .2}, PlotRange -> Full, Exclusions -> None, PlotPoints -> 50]]

enter image description here

$\endgroup$
2
  • $\begingroup$ Your function has complex values outside the region shown in the DensityPlot. In particular, in the blue region in the first plot, the values of the function are actually complex. I don't know why ListDensityPlot is plotting anything in that region. $\endgroup$
    – march
    Commented Oct 22, 2019 at 16:59
  • $\begingroup$ @march Exactly, that is strange! $\endgroup$
    – MMA13
    Commented Oct 23, 2019 at 10:27

1 Answer 1

5
+50
$\begingroup$

The problem is that ListDensityPlot discards all of the complex valued entries, and then interpolates the remaining data. One possible workaround is to replace all the complex valued entries with some number, and then adjust the plot range so that the number is out of range. For instance:

With[{trunc = Replace[Flatten[mod, 1], _Complex -> -20., {2}]},
    ListDensityPlot[trunc, PlotRange -> {0, 1}]
]

enter image description here

$\endgroup$
2
  • $\begingroup$ thanks, may you please explain the choose of -20? $\endgroup$
    – MMA13
    Commented Oct 30, 2019 at 22:43
  • $\begingroup$ @HD2006 It was just some number outside the range from 0 to 1, and a number less than 0 avoided changing the coloring. $\endgroup$
    – Carl Woll
    Commented Oct 30, 2019 at 22:45

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.