# How to put a threshold in a DensityPlot?

I've a function of two variables f(x, y) which assumes values between 0 and 1 only in a certain region of the domain of the R^2 space, i.e.

x ∈ (1, 2)

y ∈ (0, x/2)

I'm interested in a heatmap/density-plot, thus I'm doing

DensityPlot[f[x, y], {x, 1, 2}, {y, 0, 1},
ColorFunction -> "SunsetColors", Frame -> True,
FrameLabel -> {"x", "y"},
PlotLegends -> BarLegend[All, LegendLabel -> "Frequency"]]


How could I

• exclude from the density map those values not in the [0, 1] range, or
• shadow the plot area where f(x, y) is not between 0 and 1 ?

Thanks a bunch for your help!

• Look up PlotRange and ClippingStyle. – 2012rcampion Apr 22 '15 at 15:07
• The option PlotRange->{0,1}' will clip your z-values, and you can format the style of the clipping with 'ClippingStyle->"Whatever you want". I can't tell if this is what you want, or @Chip Hurst's answer. – N.J.Evans Apr 22 '15 at 15:08
• Thank you, @N.J.Evans !! I'm accepting Chip Hurst's answer but your comment will help a lot as well. – Orso Apr 23 '15 at 9:14

This is the sole purpose of RegionFunction:

DensityPlot[Sin[10 x + 10 y], {x, 1, 2}, {y, 0, 1},
ColorFunction -> "SunsetColors", Frame -> True,
FrameLabel -> {"x", "y"},
PlotLegends -> BarLegend[All, LegendLabel -> "Frequency"],
RegionFunction -> Function[{x, y}, 0 < y < x/2]
]


Edit

Another way in V10 is

R = Polygon[{{1, 0}, {1, 0.5}, {2, 1}, {2, 0}}];

DensityPlot[Sin[10 x + 10 y], {x, y} ∈ R,
ColorFunction -> "SunsetColors", Frame -> True,
FrameLabel -> {"x", "y"},
PlotLegends -> BarLegend[All, LegendLabel -> "Frequency"],
PlotPoints -> 40
]

• A big "thank you", @Chip Hurst !!! That's exactly what I was looking for. – Orso Apr 23 '15 at 9:16