In research, one way to gain insight is to be creative about how you visualize your data. This is central in being able to visualize datasets as diverse as genome sequences or gene expression patterns. This can even showcase interesting properties of something as fundamental as numbers.

One creative visualization of numbers is called the Ulam Spiral. The procedure starts with placing 1 in the center of an arbitrary grid and as the numbers increase you arrange them in a spiraling pattern. Below you can see the result of a function that generates such a spiral as a two-dimensional numpy array.

The spiral depiction itself is not that interesting - but what occurs after we color cells of the spiral by whether they are prime or not is quite interesting. Ulam spiral of size 500 x 500

We can see that there are some diagonal lines that appear quite consistently. Note that the way I have constructed the spiral is such that it goes clockwise as the numbers ascend - as opposed to the diagrams on wikipedia that go counter clockwise. Regardless, the appearance of these diagonal lines are interesting because they suggest that there may be a consistent pattern that dictates the presence of prime numbers, a longstanding problem in number theory. Prime numbers are also central to many of our underlying computer security systems, forming a critical component of modern cryptography.

In addition, we can further visualize not only whether a number is prime or not but the number of divisors that each number in the spiral has. This quickly gets high as numbers get larger, therefore we will plot the log of the number of divisors as the heat. Ulam spiral of size 500 x 500 (colored by log of the number of divisors)

To recreate the figures in this post you can download or use the code from this ipython notebook