Prime Numbers – Meaning of Rays in Polar Plot

polar coordinatesprime numbers

I recently began experimenting with gnuplot and I quickly made an interesting discovery. I plotted all of the prime numbers beneath 1 million in polar coordinates such that for every prime $p$, $(r,\theta) = (p,p)$. I was not expecting anything in particular, I was simply trying it out. The results are fascinating.

When looking at the primes beneath 30000, a spiral pattern can be seen:
Primes Beneath 30000

For comparison, here is the same graph with the multiples of 3 and 7 superimposed on it. Primes are in yellow, multiples of 3 and 7 in green and red respectively.
Primes Beneath 30000 with Multiples of 3 and 7

What is really interesting to me, though, is the behavior when the range is increased. Multiples of a given number appear to spiral out in the same pattern into infinity, but the primes begin to form rays in groups of 3 or 4. See below:
Primes Beneath 200000

Primes Beneath 1 Million

Compared to multiples of 3 and 7 again:
Primes Rays, Multiple Spirals

Now, I must admit that I am very much a novice mathematician with little experience beyond trigonometry. I am just going into Calculus and Discrete Mathematics this upcoming fall.

I know that there is something called the Prime Number theorem – are these patterns related to it? Are these rays the same phenomenon as the diagonal lines found in Ulam Spirals?

EDIT:
In response to Greg Martin's explanation, I decided to add a couple more graphs. To see why they are relevant, read his answer.

$(r,\theta)=(n,n), n \in \mathbb{N}$

Progression 1

Progression 2

Best Answer

What we're seeing is arithmetic progressions (not prime-producing polynomials) of primes, combined with a classical phenomenon about rational approximations.

When the integers (or any subset of them) are represented by the polar points $(n,n)$, of course integers that are close to a multiple of $2\pi$ apart from each other will lie close to the same central ray. Figuring out when integers are close to a multiple of $2\pi$ apart is a perfect job for continued fractions. The continued fraction of $2\pi$ is $\langle 6; 3,1,1,7,2,146,\dots\rangle$, giving the convergents $$ \left\{6,\frac{19}{3},\frac{25}{4},\frac{44}{7},\frac{333}{53},\frac{710}{113},\frac{103993}{16551},\dots\right\}, $$ which are the rational approximations of $2\pi$ that will dominate the picture on different scales.

For example, if you plot the polar points $(n,n)$ for $1\le n\le 25000$, you will notice the points aligning themselves into $44$ spirals: jumping ahead from $n$ to $n+44$ is almost the same as going around the circle $7$ times (note the convergent $\frac{44}7$ showing up); moving from $n$ to $n+1$ jumps ahead $7$ spirals. Each spiral corresponds to an arithmetic progression $a\pmod{44}$; going from one spiral to the next one counterclockwise corresponding to changing the arithmetic progression from $a\pmod{44}$ to $a+19\pmod{44}$ (note that $19\equiv7^{-1}\pmod{44}$).

If instead you plot only the primes $(p,p)$, you will get reasonable representation in the $\phi(44)=20$ spirals corresponding to arithmetic progressions $a\pmod{44}$ where $\gcd(a,44)=1$, and no primes in the other $24$ spirals. That's what we're seeing in the top two pictures.

As the scale moves farther out, these particular spirals become more tightly wound and harder to see (go from the 1st picture to the 5th, then the 3rd, then the 4th), and the next convergent takes over. In this case, the convergent $\frac{710}{113}$ is an extremely good rational approximation to $2\pi$ (as we know from the large partial quotient $146$). Therefore the integer points $(n,n)$ will group themselves into $710$ spirals, but these spirals are so close to straight lines at the beginning that they almost don't look like spirals, and persist for a large interval of possible scales. Each ray thus corresponds to an arithmetic progression $a\pmod{710}$.

When we plot only prime points $(p,p)$ (the 4th picture is best here), we will only see the $\phi(710)=280$ arithmetic progressions $a\pmod{710}$ where $\gcd(a,710)=1$. The fact that the visible rays are mostly grouped in fours is a consequence of the fact that $5\mid710$ and so every fifth ray doesn't contain primes. Really, though, we are seeing four out of every ten rays rather than four out of every five; the arithmetic progressions $a\pmod{710}$ with $a$ even have no primes at all and are thus invisible. There are four exceptional groups containing only three rays instead of four; these correspond to the four arithmetic progressions $a\pmod{710}$ where $a$ is a multiple of $71$ but not a multiple of $2$ or $5$.