3
$\begingroup$

I want to create a 2D scatter plot using roots found by the Reduce function; i.e., all integer points on a circle.

Enter image description here

Reduce[x^2 + y^2 == 5^2, {x, y}, Integers]

How do I achieve this?

$\endgroup$
2
  • 1
    $\begingroup$ In this very special case, try ListPlot[Reduce[x^2 + y^2 == 5^2, {x, y}, Integers] /. {And | Or -> List, _ == a_ :> a}]. But this is fragile and only works because the output is structured so nicely. $\endgroup$
    – thorimur
    Commented Nov 15, 2022 at 6:13
  • 1
    $\begingroup$ ListPlot[SolveValues[x^2 + y^2 == 5^2, {x, y}, Integers], AspectRatio -> 1] $\endgroup$
    – Bob Hanlon
    Commented Nov 15, 2022 at 16:32

4 Answers 4

5
$\begingroup$
sol = Reduce[x^2 + y^2 == 5^2, {x, y}, Integers];
reg = ImplicitRegion[sol, {x, y}];
Region[reg, BaseStyle -> {PointSize[Large], Red}]

enter image description here

$\endgroup$
1
  • $\begingroup$ +1. I like it because this is a natural way. $\endgroup$
    – user64494
    Commented Nov 15, 2022 at 6:29
4
$\begingroup$
pts = {x, y} /. {ToRules[Reduce[x^2 + y^2 == 5^2, {x, y}, Integers]]}
circ = CircleThrough[RandomChoice[pts, 3]]

ListPlot[pts
 , PlotStyle -> Directive[Black
   , AbsolutePointSize[6]]
 , AspectRatio -> Automatic
 , Epilog -> {
   Dashed, Red, circ
   }
 ]

enter image description here


A labeled variant:

ListPlot[Callout[#, #] & /@ pts
 , PlotStyle -> Directive[Black
   , AbsolutePointSize[6]]
 , AspectRatio -> Automatic
 , Frame -> True
 , Epilog -> {
   Dashed, Red, circ
   }
 ]

enter image description here

$\endgroup$
2
$\begingroup$

Inelegant, but revealing:

jj = Reduce[x^2 + y^2 == 25, {x, y}, Integers];

kk = Table[{jj[[i, 1, 2]], jj[[i, 2, 2]]}, {i, Length[jj]}];

Graphics[{Red, PointSize[0.02], Point /@ kk}, GridLines -> {Range[-5, 5], Range[-5, 5]}]

enter image description here

$\endgroup$
2
$\begingroup$

I am sure there are 10 ways to do this. One another way could be

sol = Reduce[x^2 + y^2 == 5^2, {x, y}, Integers];
List @@ Map[{First[#][[2]], Last[#][[2]]} &, sol];
Graphics[{
  {Opacity[.1], Blue, Disk[]},
  {Red, PointSize[0.02], Point[points]},
  {Text[ToString[#], #, {-1.5, 0}] & /@ points}
  },
 Axes -> True]

Mathematica graphics

If you do not want the disk, you can remove it.

$\endgroup$

Your Answer

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

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