0
$\begingroup$

I have a simple contour plot and wanted to find solutions only when both x and y are integers. The following code doesn't seem to work.

ContourPlot[{4 x == 3 y, {x, y} \[Element] Integers}, {x, 0, 20}, {y, 0, 20}]

For the above code I was expecting the plot to have a few dots that satisfy the equations, instead the code just gives a continuous line.

How would I do it?

thanks,

$\endgroup$
1
  • 1
    $\begingroup$ ListPlot[{x, y} /. Solve[{4 x == 3 y, 0 <= x <= 20, 0 <= y <= 20}, {x, y}, Integers]]? $\endgroup$
    – kglr
    May 26, 2016 at 3:35

1 Answer 1

1
$\begingroup$
ContourPlot[{4 x == 3 y, {x, y} ∈ Integers},
 {x, 0, 20}, {y, 0, 20},
 ContourStyle -> Thin, Epilog -> {Red, AbsolutePointSize[6],
   Tooltip[Point[#], #] & /@
    ({x, y} /. 
      Solve[{4 x == 3 y, 0 <= x <= 20, 0 <= y <= 20},
       {x, y}, Integers])}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.