# RegionPlot strange problem

I have strange problem with Wolfram Mathematica's function RegionPlot

RegionPlot[x - y == 0, {x, 0, 100}, {y, 0, 100}]


the result is:

But when I try

RegionPlot[x - y == 1, {x, 0, 100}, {y, 0, 100}]


Do you know what I am doing wrong? Thanks!

• Documentation states that "RegionPlot will only visualize two-dimensional regions: ". So, the question is, why did the first plot show a line? Feb 28 '16 at 15:53
• I'm doing exercise in which I need to use function RegionPlot to draw a line, but I guess there must be an error in exercise. Feb 28 '16 at 16:01
• There is not an error in your exercise!
– user36273
Feb 28 '16 at 16:17

Starting with v10.0 you can use InfiniteLine

RegionPlot[
InfiniteLine[{x, x - 1} /. {{x -> 0}, {x -> 1}}],
PlotRange -> {0, 100}]


What do you want

ContourPlot[x - y == 1, {x, 0, 100}, {y, 0, 100}]


or should it be

RegionPlot[x - y < 1, {x, 0, 100}, {y, 0, 100}]


Addendum for exercise. You have to define a region!

reg = ImplicitRegion[x - y == 1, {x, y}];
RegionPlot@reg


reg = ImplicitRegion[x - y == 1 && 0 < x < 100 && 0 < y < 100, {x, y}];
RegionPlot@reg


RegionPlot will only visualize two-dimensional regions. See the documentation "Possible Issues".

• I'm doing exercise in which I need to use function RegionPlot to draw a line. Feb 28 '16 at 15:57
• @rewi Why did the first example work? This seems to be a one-dimensional region which violates the Possible Issues in the documentation. Feb 28 '16 at 16:20
• @Jack LaVigne Unfortunately, I also know not all :)
– user36273
Feb 28 '16 at 16:24
• @JackLaVigne The example in possible issues seems to need modification since the introduction of ImplicitRegions Feb 28 '16 at 19:39

Correction:

RegionPlot[x - y == 1, {x, 0, 100}, {y, -1, 99}]


Why does it work? Consider the following example. RegionPlot understands True statement (put any a).

With[{a = 50},
RegionPlot[x - y == a, {x, 0, 100}, {y, 0 - a, 100 - a}]]


• +1 I think you have nailed it. Excellent explanation. Feb 28 '16 at 22:05

Due to the sampling pattern used by RegionPlot, it is lucky that it finds the line in your first example. Consider the output of

noisyFunction[x_, y_] := Module[{},
Sow[{x, y}];
x - y
];
ListPlot[
Take[
Reap[
RegionPlot[noisyFunction[x, y] == 0, {x, 0, 100}, {y, 0, 100}]
][[2, 1]],
{4, -1}]
]


The clustering of samples around the line is easily seen. But RegionPlot is not lucky for your second example.

ListPlot[
Take[
Reap[
RegionPlot[noisyFunction[x, y] == 1, {x, 0, 100}, {y, 0, 100}]
][[2, 1]],
{4, -1}]
]


One should use EvaluationMonitor if one is going to be serious about inspecting the evaluation set of a function fed to a plot or numerical search.