Last active
December 24, 2018 13:21
-
-
Save anant347/0da58e180f6e2025d96de74f47ec2b24 to your computer and use it in GitHub Desktop.
Prime Numbers art
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Prime Art | |
import time | |
start = time. time() | |
import math as m | |
import matplotlib.pyplot as plt | |
import numpy as np | |
file="primes1.txt" #downloaded from "https://primes.utm.edu/lists/small/millions/" (removed first and last line) | |
with open(file,'r') as file: | |
d=file.readlines() | |
p=[] | |
X=10000 #Till what number (Change this to a perfect square ex. 64, 100, 10000, 1000000) | |
for i in d: | |
for j in i.split(): | |
p.append(float(j)) #Primes stored in 'p' | |
gd=int(m.sqrt(X)) #grid dimensions | |
x=[] | |
y=[] | |
for i in p[:X]: | |
if i<=X: | |
x.append(i%gd) | |
y.append(gd-int(i/gd)) | |
fig, ax=plt.subplots(figsize=(10,10)) #10 inches x 10 inches | |
for spline in plt.gca().spines.values(): | |
spline.set_visible(False) | |
plt.tick_params(top=False,bottom=False,left=False, right=False, labelleft=False, labelbottom=False) | |
plt.yticks(np.linspace(1,gd,gd)) | |
plt.xticks(np.linspace(1,gd,gd)) | |
plt.grid(b=1, linewidth=0.5, alpha=0.5) | |
plt.scatter(x,y,marker='o', c='black', s=12) | |
ax.set_axisbelow(True) | |
end=time.time() | |
print('ExTime: ',end-start) | |
plt.savefig('primeart1.png',bbox_inches='tight',dpi=600) |
Author
anant347
commented
Dec 24, 2018
- Download the primes from "https://primes.utm.edu/lists/small/millions/" (remove the first and last line)
- Set 'X' to the value till which you want to plot the primes (set to a perfect square)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment