Update: An alternative way to use ContourPlot
using threshold
as the single Contour
with the option ContourShading
:
threshold = .5;
ContourPlot[FractionalPart[y + Sin[x^2 + 3 y]], {x, -3, 3}, {y, -3, 3},
Contours -> {threshold}, ContourShading -> {Black, White},
Exclusions -> None, PlotPoints -> 90]
Similarly, DensityPlot
with MeshFunctions
, Mesh
and MeshShading
options:
DensityPlot[FractionalPart[y + Sin[x^2 + 3 y]], {x, -3, 3}, {y, -3, 3},
MeshFunctions -> {#3 &}, Mesh -> {{threshold}},
MeshShading -> {Black, White}, PlotPoints -> 90,
Exclusions -> None, WorkingPrecision -> 10]
And, a combination of Raster
and Image
:
Image @ Raster[Table[UnitStep[FractionalPart[y + Sin[x^2 + 3 y]] - threshold],
{y, -3, 3, 1/100}, {x, -3, 3, 1/100}]]
We get the same picture using Boole[FractionalPart[y + Sin[x^2 + 3 y]] >= threshold]
instead of UnitStep[FractionalPart[y + Sin[x^2 + 3 y]] - threshold]
.
Original answer:
You can use ContourPlot
with options Contours
and ContourShading
:
threshold = .5;
ContourPlot[y + Sin[x^2 + 3 y], {x, -3, 3}, {y, -3, 3},
Contours -> {threshold}, ContourShading -> {Black, White}]
Another alternative is to use RegionPlot
:
RegionPlot[y + Sin[x^2 + 3 y] <= threshold, {x, -3, 3}, {y, -3, 3} ,
BoundaryStyle -> Black, PlotStyle -> Black, PlotPoints -> 100]
With DensityPlot
you can do
DensityPlot[y + Sin[x^2 + 3 y] , {x, -3, 3}, {y, -3, 3},
ColorFunction -> (Black &), RegionFunction -> (#3 <= threshold &)]
You can also use DensityPlot
with the option ColorFunction
with large enough value for PlotPoints
to get a similar picture the one above:
cf1 = If[# <= threshold, Black, White] &;
DensityPlot[y + Sin[x^2 + 3 y], {x, -3, 3}, {y, -3, 3},
ColorFunction -> cf1, PlotPoints -> 250]
Using cf2 = Blend[{Black, White}, UnitStep[# - threshold]] &;
in place of cf1
gives the same result.