Shown below is the Plot3D and DensityPlot of a dataset i have generated. I want to be able to see the peaks shown in the plot3d on the density plot but they don't seem to show up and I was wondering if there was a way to fix this? 3dplotdensity plot

Also, if possible I was wondering if there was a way (either for the density plot or the 3d plot) to make the plotting region hexagonal. The usual method i use (creating a hexregion and assigning it to the regionfunction) seems to create something Lovecraftian...

lovecraftian horror

The relevant code is here:

    anew = {{1, 0}, {1/2, Sqrt[3]/2}};
d = {{Cos[kvec . anew[[1]]] + Cos[kvec . anew[[2]]] + 
     1}, {Sin[kvec . anew[[1]]] + Sin[kvec . anew[[2]]]}, {delta + 
       phi]*(Sin[kvec . anew[[1]]] - Sin[kvec . anew[[2]]] - 
        Sin[kvec . (anew[[1]] - anew[[2]])])}};
Inner[Times, PauliMatrix[Range[3]], d, Plus, 1];
ham2[kx_, ky_, delta_, t2_, phi_] = %[[All, All, 1]];
ham2[KX, KY, DELTA, T2, PHI] // MatrixForm

kxrange = N[Range[-2*Pi + Pi/100, 2*Pi - Pi/100, 4*Pi/100]];
kyrange = N[Range[-2*Pi + Pi/100, 2*Pi - Pi/100, 4*Pi/100]];
t2val = 0.0;
phival = Pi/2;
deltaval = 0.1;
ham2[KX, KY, deltaval, t2val, phival];
ham = %;
Eigensystem[ham2[KX, KY, deltaval, t2val, phival]];
{anaeigvals, anaeigvecs} = %;
I*(Conjugate[D[anaeigvecs, KX]] . D[anaeigvecs, KY] - 
    Conjugate[D[anaeigvecs, KY]] . D[anaeigvecs, KX]);
berry[KX_, KY_] = %;
hexRegion = Region[RegularPolygon[2 \[Pi], 6]];
Plot3D[Re[berry[KX, KY]], {KX, -2*Pi, 2*Pi}, {KY, -2*Pi, 2*Pi}, 
 RegionFunction -> Function[{x, y, z}, {x, y} \[Element] hexRegion]]
  • 1
    $\begingroup$ Have a look at "ham2" it does not depend on kx and ky. $\endgroup$ Apr 28, 2022 at 16:21
  • $\begingroup$ When I run your code on version 12.3 I get: i.stack.imgur.com/mR0aO.png $\endgroup$ Apr 28, 2022 at 16:48
  • $\begingroup$ Ah apologies! You just need to define kvec={kx,ky}. That was an error on my part. For reference, the code cited is the attempt to ply over the hecagonal region - if you just remove the RegionFunction part of the code you will obtain the graphs above. $\endgroup$ Apr 28, 2022 at 19:17
  • $\begingroup$ The lovecraftian plot has PlotRange {-.5 10^-16, .5 10^16}. What you are seeing is numerical artifacts. Usually Mathematica can get the right range automatically, in this case it doesn't. Set PlotRange->{-1,1} to obtain a more sensible plot (though it seems to be multivalued) imgur.com/a/tTjjbhe. $\endgroup$
    – Adam
    Apr 28, 2022 at 20:30

1 Answer 1


In the very last line where you are plotting, use Chop.

Plot3D[Chop[Re[berry[KX, KY]]], {KX, -2*Pi, 2*Pi}, {KY, -2*Pi, 2*Pi}, 
 RegionFunction -> Function[{x, y, z}, {x, y} \[Element] hexRegion]]

This is because, as you can see in your plot the numerical outputs are of the order of $10^{-16}$, which is zero with respect to peak values.

enter image description here

Or you can also use PlotRange -> Full.

Plot3D[Re[berry[KX, KY]], {KX, -2*Pi, 2*Pi}, {KY, -2*Pi, 2*Pi}, 
RegionFunction -> Function[{x, y, z}, {x, y} \[Element] hexRegion], 
PlotRange -> Full]

It will give you the same result.

  • $\begingroup$ Ah thank you that's really helpful! $\endgroup$ Apr 29, 2022 at 12:39
  • $\begingroup$ I was wondering if its possible to make the colorfunction show a change in colors for the peaks? for some reason it doesn't seem to show up at all. $\endgroup$ Apr 29, 2022 at 13:01

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.