So I have a set of bounded diophantine equations that specify lines on the plane. I want to make mathematica plot the intersection of two of these equations so I can see what they look like.
So far I have something like:
Solve[0 < x - y < 3 && -1 < 2 x - y < 2, {x, y}, Integers]
which returns some structure like:
{{x -> -2, y -> -4}, {x -> -1, y -> -3}, {x -> -1, y -> -2}, {x -> 0, y -> -1}}
but how can I now make mathematica plot this so I can see the resulting shape. Preferably I would like the plot to consider every 'point' to be a 1x1 square.
Also, I wonder if there is a better way to do such things. Thanks.
Define the data you wish to plot by transforming the list
Solve[]
returns. This can done asMore generally, you can make
Solve
return the solution in a list format (rather than as a set of rules) using the following trick:For plotting, among many alternatives, you can use
ListPlot
asto get the following output
You can further refine it using many styling and other options of
ListPlot
. For example, you can join the pointsto get
EDIT: To play with the marker placement and size there are several alternatives. Using
ListPlot
you can get what you need in either of the two ways:In both cases, you need to use
Epilog
, otherwise the lines joining points are occluded by the markers. Both alternatives produce the following output:Alternatively, you can use
Graphics
,RegionPlot
,ContourPlot
,BubbleChart
with appropriate transformations ofdata
to get results similar to the one inListPlot
output above.Using Graphics primitives:
Using BubbleChart:
Using RegionPlot:
Using ContourPlot: