# Highlight integer points in RegionPlot

Is there any way to mark integer points after plotting region in Mathematica? For example, if I:

RegionPlot[x >= 4 y && x <= 4 y + 3 , {x, 0, 63}, {y, 0, 15}]


then it highlights the region but I want to see Y value corresponding to integer X value. Can I do it with Mathematica?

-
I added a graphic to your post to help illustrate. Could you describe in more detail what you expect to see, please? –  Mr.Wizard Dec 11 '12 at 16:39
Like in above image I want to mark (x,y) where both x and y are integers. –  username_4567 Dec 11 '12 at 16:44
You might want to wait a bit with the accept, as others may provide better answers. –  István Zachar Dec 11 '12 at 17:00
Yes I can do that .. –  username_4567 Dec 11 '12 at 17:01

Use the inequality to sow all integer coordinates that are inside the boundary of the region when iterating through all integer pairs of the full range:

pts = First@Last@Reap@Do[If[x >= 4 y && x <= 4 y + 3, Sow@{x, y}], {x, 0, 63}, {y, 0, 15}]
RegionPlot[x >= 4 y && x <= 4 y + 3, {x, 0, 63}, {y, 0, 15}, Epilog -> {Red, Point@pts}]


-
Amazing..Thanks a lot.. –  username_4567 Dec 11 '12 at 16:58

Another way to generate all the points is by using Reduce:

points = {x, y} /.
List@ToRules@
Reduce[x >= 4 y && x <= 4 y + 3 && 0 < x < 63 && 0 < y < 15, {x, y}, Integers]


If you give bounds (and thus constrain the possible solutions to a finite set), Reduce will typically list all solutions.

Then just plot them with Point or ListPlot:

ListPlot[points]


Show them together with the RegionPlot:

Show[ListPlot[points], RegionPlot[...]]


Thanks to Mr.Wizard to pointing me to the following relevant note in the documentation:

Mathematica enumerates the solutions explicitly only if the number of integer solutions of the system does not exceed the maximum of the $p^{\text{th}}$ power of the value of the system option DiscreteSolutionBound, where $p$ is the dimension of the solution lattice of the equations, and the second element of the value of the system option ExhaustiveSearchMaxPoints.

-
Might want to mention ExhaustiveSearchMaxPoints. +1 –  Mr.Wizard Dec 11 '12 at 18:29
@Mr.Wizard Thanks for the pointer. I didn't know about this option. –  Szabolcs Dec 11 '12 at 23:42
I changed your documentation link to an anchor I thought was more appropriate. If you disagree change it back, or perhaps add a second one. –  Mr.Wizard Dec 12 '12 at 19:30
@Mr.Wizard I agree, but I am usually too lazy to dig out the precise anchor (if it is not linked to and I can't just copy the link). Is there an easier way than using the dev tools of the browser or looking at the web page source? –  Szabolcs Dec 13 '12 at 0:23
There's a Meta post about that. I still use View Selection Source myself; it really doesn't take long. If your browser only lets you view the source of the entire page I can see the problem. –  Mr.Wizard Dec 13 '12 at 1:36

Alternatively you can generate just the points you want and then plot them :

data = DeleteCases[Flatten[Outer[Boole[4 #2 <= #1 <= 4 #2 + 3] {#1, #2} &,
Range[0, 63], Range[0, 15]], 1], {0, 0}];

Show[RegionPlot[x >= 4 y && x <= 4 y + 3, {x, 0, 63}, {y, 0, 15}],  ListPlot[data]]


-

Another, using smart and fast functions like Array and Tuples, thus a bit more recommended way :

RegionPlot[ x >= 4 y && x <= 4 y + 3, {x, 0, 63}, {y, 0, 15}, Epilog -> {
Red, PointSize[0.005],
Point[ Join @@ Tuples /@ Array[ {Range[4 #, 4 # + 3], {#}} &, {16}, 0]]},
AspectRatio -> 15/63 ]


-
By the way, you can just do AspectRatio -> Automatic... –  Rahul Dec 12 '12 at 2:30
@RahulNarain That's all ? –  Artes Dec 12 '12 at 19:04
I mean, instead of manually specifying 15/63. –  Rahul Dec 12 '12 at 21:49