Skip to main content

plotting - Create a nonlinear color function


I'm doing density plots in Mathematica where I mostly plot Wigner functions.


The main objective when plotting a Wigner function is to demonstrate that the underlying state is nonclassical, as indicated by negative values in the Wigner function. Therefore I want to make these negative values stand out in the plot.


To demonstrate this, I've plotted the Wigner function of an even cat state


cat state



which was generated using the following code


(* Plots the Wigner function of an even Cat State *)
α = Sqrt[
16];
Wigner[x_, y_] :=
1/(π Sqrt[
1 + Exp[-2 α^2]]) (Exp[-2 (x - α)^2 - 2 y^2] +
Exp[-2 (x + α)^2 - 2 y^2] +
2 Exp[-2 x^2 - 2 y^2]*Cos[4 y α]);


DensityPlot[Wigner[x, y], {x, -6, 6}, {y, -2, 2},
PlotRange -> All,
ColorFunction -> "LightTemperatureMap",
PlotLegends -> Placed[
BarLegend[
{"LightTemperatureMap", {-.5, .5}},
LegendMargins -> {{26, 20}, {-15, 0}},
LegendMarkerSize -> {475, 30}],
Above],
ImagePadding -> {{45, 20}, {45, 10}},

PlotRangePadding -> None,
ImageSize -> {600, 200},
AspectRatio -> Automatic,
FrameLabel -> {"x", "y"},
FrameTicks -> {{{-2, 0, 2}, None}, {Table[-6 + 2 i, {i, 0, 6}],
None}},
FrameStyle -> Black,
FrameTicksStyle -> Directive[Black, 14],
LabelStyle -> {Black, Bold, 14},
PlotPoints -> 50

]

As you can see in the figure above, it's difficult to distinguish positive and negative values around the zero value.


All of the color functions that I've found in Mathematica are linear colormaps where small negative values tend to be near the same color as the zero values, and are thus hidden. I'm looking for a nonlinear color function that colors all negative values differently than positive or zero values


See for example the right figure down below wigner colormap



Answer



If you want abrupt changes in color, Piecewise seems more appropriate.


colorWig[z_] := Piecewise[{{GrayLevel[1 - z], 0 < z < 1},
{Hue[.3, 1, 1 + z], -1 < z < 0}}]


DensityPlot[Sin[x y], {x, -1, 1}, {y, -1, 1},
ColorFunction -> colorWig, ColorFunctionScaling -> False,
PlotPoints -> 50]

plot


Comments