In [ ]:
def eratosthenes_sieve(n):
  primes_index = [True,]*n

  for i in range(2, n):
    for j in range(i**2, n, i):
      primes_index[j]=False
  return [i for i in range(0, len(primes_index)) if primes_index[i]][2:]
In [ ]:
eratosthenes_sieve(20)
Out[ ]:
[2, 3, 5, 7, 11, 13, 17, 19]
In [ ]:
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
#import matplotlib.animation as animation 
from matplotlib.animation import FuncAnimation, writers
from IPython.display import HTML
In [ ]:
all_numbers = list(range(1, 2000))
primes = eratosthenes_sieve(2000)
In [ ]:
def plot_numbers(ax, primes, all_numbers):
  pi_n = len(primes)
  num_length = len(all_numbers)
  
  ax[0].set_title('Primes',fontsize=14, color='red')
  ax[0].set_rticks(range(0, num_length, 500))
   
  ax[1].set_rticks(range(0, num_length, 500))
  ax[1].set_title('All Numbers', color='blue')
  [i.grid(False) for i in ax]
  return ax[0].scatter(primes, primes,marker='+', color = 'r' ),ax[1].scatter(all_numbers,all_numbers, color='blue',marker='+')
In [ ]:
def animatex(i):
  return ax[0].scatter(primes[:i], primes[:i],marker='+', color = 'r' ), ax[1].scatter(all_numbers[:i],all_numbers[:i], color='blue',marker='+')
ani = FuncAnimation(fig, animatex, frames=800)
HTML(ani.to_html5_video())
In [ ]:
fig, ax = plt.subplots(nrows=1, ncols=2,facecolor='grey',subplot_kw=dict(projection='polar'),figsize=(16, 12))
plot_numbers(ax, primes, all_numbers)
Out[ ]:
(<matplotlib.collections.PathCollection at 0x7f3e5e6e3490>,
 <matplotlib.collections.PathCollection at 0x7f3e5e6e3bd0>)
In [ ]:
fig0, ax0 = plt.subplots(nrows=1, ncols=2,facecolor='grey',subplot_kw=dict(projection='polar'),figsize=(16, 12))
primes_square = np.array(eratosthenes_sieve(4000))
all_numbers_square = np.array(range(1, 4000))
plot_numbers(ax0, primes_square, all_numbers_square)
Out[ ]:
(<matplotlib.collections.PathCollection at 0x7f3e5daf4610>,
 <matplotlib.collections.PathCollection at 0x7f3e5db52790>)
In [ ]: