Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3.  
  4. MAX_PRIME = 8000
  5.  
  6.  
  7. def isprime(n):
  8.  
  9.     if n <= 1:
  10.         return False
  11.     for num in range(2, int(np.sqrt(n)) + 1):
  12.         if not n % num:
  13.             return False
  14.     else:
  15.         return True
  16.  
  17. def getnprimes(n):
  18.  
  19.     primes = []
  20.  
  21.     for num in range(n):
  22.         if isprime(num):
  23.             primes.append(num)
  24.  
  25.  
  26.     return primes
  27.  
  28. primes = getnprimes(MAX_PRIME)
  29.  
  30. ax = plt.subplot(111, projection = "polar")
  31. ax.scatter(primes, primes, s = 1)
  32.  
  33. plt.xlabel("x")
  34. plt.ylabel("y")
  35.  
  36. plt.title("Graph")
  37.  
  38. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement