“Can the code be improved?”. The first step takes a long time.
First find the values of z = Sqrt[x^2 + y^2] for x and y integers between 1 and 10,000
t = Flatten[Table[{{x, y}, Sqrt[x^2 + y^2]}, {x, 10^4}, {y, 10^4}],
1];
Next find the points with z an integer
In[2]:= Length[s = Select[t, IntegerQ[#[[2]]] &]]
Out[2]= 28948
ListPlot {x,y}. Many of the points are multiples of small value solutions.
Now select the points where x and y have no common factors
In[4]:= Length[ss = Select[s[[All, 1]], GCD[Sequence @@ #] == 1 &]]
Out[4]= 3576
Plot those points

