The following command
DensityPlot[x y, {x, -3, 3}, {y, -3, 3}, PlotLegends -> Automatic,
ColorFunction -> {"Rainbow"}, PlotRange -> {{-3, 3}, {-3, 3}}]
gives the following output:
I know that I can change the scale of the coloring in DensityPlot using PlotRange. I.e., the following command
DensityPlot[x y, {x, -3, 3}, {y, -3, 3}, PlotLegends -> Automatic,
ColorFunction -> {"Rainbow"}, PlotRange -> {{-3, 3}, {-3, 3}, {-1, 1}}]
gives the following output:
In the second plot, the red color is assigned to the value $1$ and the purple color to the value $-1$. Question: is there a way to change the colors in the DensityPlot such that such that the red color is assigned to all values $\geq 1$, and similarly the purple color to $\leq 1$? So basically, I would like to obtain the second plot, where the four white corners are then colored red (upper left & lower right) or purple (upper right & lower left).
(Actually I'm using ListDensityPlot instead of DensityPlot, but I'm assuming this is similar.)
Clip[]
and the option settingColorFunctionScaling
. $\endgroup$ClippingStyle
is better suited to what he's asking for. $\endgroup$ColorFunction -> ColorData[{"Rainbow", {-1, 1}}, Clip[(* stuff *)]]
, and yours is certainly more idiomatic. $\endgroup$