The Klauber Triangle

(0 comments)

enter image description here

The Klauber Triangle (first proposed by the American herpetologist Laurence Monroe Klauber) is a simple way to visualize the prime numbers, similar to the Ulam Spiral. It is constructed by creating a triangle of the natural numbers and then highlighting only the primes:

       1                   □
     2 3 4        →      ■ ■ □
   5 6 7 8 9           ■ □ ■ □ □
 ...                 ...

Here is a short Python script to generate the Klauber Triangle above.

This code is also available on my github page.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm

n = 200
ncols = 2*n+1
nmax = n**2

# Prime numbers up to and including n**2.
primes = np.array([n for n in range(2,n**2+1) if all(
                        (n % m) != 0 for m in range(2,int(np.sqrt(n))+1))])
a = np.zeros(nmax)
a[primes-1]=1

arr = np.zeros((n, ncols))
for i in range(n):
    arr[i,(n-i):(n+i+1)] = a[i**2:i**2+2*i+1]

fig, ax = plt.subplots()
ax.matshow(arr, cmap=cm.binary)
ax.axis('off')
# Ensure the Axes are centred in the figure
ax.set_position([0.1,0.1,0.8,0.8])
plt.show()
Current rating: 4.4

Comments

Comments are pre-moderated. Please be patient and your comment will appear soon.

There are currently no comments

New Comment

required

required (not published)

optional

required