1
$\begingroup$

I currently have this code,

psi = a (Sin[2*Pi*x] Sin[3*Pi*y] + .5 Sin[3*Pi*x] Sin[2*Pi*y]);
psip = Abs[psi]^2;
psipp = Integrate[psip, {x, 0, 2}, {y, 0, 2}]
Solve[psipp == 1, a, Reals]
b = 0.894427;
psii = b (Sin[2*Pi*x] Sin[3*Pi*y] + .5 Sin[3*Pi*x] Sin[2*Pi*y]);
DensityPlot[psii, {x, 0, 2}, {y, 0, 2}, ColorFunction -> "Rainbow", 
PlotLegends -> Automatic, 
PlotRange -> {Automatic, Automatic, {-5, 5}}]

I now want the density plot to only show where my zeros are and positive and negative numbers. Like if its zero the color would be black, if positive, green, and if negative, red. Something like that. Does any one know how I would go about getting this done?

Thank you

$\endgroup$
  • $\begingroup$ Did you check ContourPlot? Note that you are not using psip, psipp and Solve[...] so there no need to overcomplicate the question. $\endgroup$ – anderstood Feb 21 '18 at 1:30
2
$\begingroup$
b = 0.894427;
psii = b (Sin[2*Pi*x] Sin[3*Pi*y] + .5 Sin[3*Pi*x] Sin[2*Pi*y]);

DensityPlot

DensityPlot[psii, {x, 0, 2}, {y, 0, 2}, 
 PlotLegends -> BarLegend[{{Red, Green}, {-2, 2}}, {-2, 0, 2}], 
 PlotRange -> {Automatic, Automatic, {-5, 5}}, 
 MeshFunctions -> Function[{x, y}, psii], Mesh -> {{0}}, 
 MeshStyle -> Directive[Thick, Black], PlotPoints -> 100, 
 MeshShading -> {Red, Green}]

enter image description here

ContourPlot

ContourPlot[psii, {x, 0, 2}, {y, 0, 2}, 
 PlotLegends -> BarLegend[{{Red, Green}, {-2, 2}}, {-2, 0, 2}], 
 PlotRange -> {Automatic, Automatic, {-5, 5}}, Contours -> {{0}}, 
 ContourStyle -> Directive[Thick, Black], PlotPoints -> 100, 
 ContourShading -> {Red, Green}]

enter image description here

$\endgroup$
  • $\begingroup$ Is there a reason why there is aliasing with DensityPlot? $\endgroup$ – anderstood Feb 21 '18 at 2:13
  • $\begingroup$ @anderstood, good question; I don't know why. $\endgroup$ – kglr Feb 21 '18 at 2:22

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.