-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlotPrimes.py
38 lines (31 loc) · 883 Bytes
/
PlotPrimes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
import libprimes
import sys
import prettyplotlib as ppl
import numpy as np
import matplotlib.pyplot as plt
if __name__ == '__main__':
# Parse command line options
if len(sys.argv) <= 1:
print("Please set loop numbers")
sys.exit()
n = int(sys.argv[1])
N = 10**n
div = 100
step = N / div
x = np.arange(2, N, step, dtype=int)
ri = libprimes.Ri4(x)
delta = np.r_[step / np.log(step), np.diff(ri)]
primes = libprimes.primesfrom3to(N)
# Compute histogram
hist = np.histogram(primes, bins=div)
y = hist[0]
# Graph
plt.ylabel('Count of primes')
plt.ticklabel_format(style='sci', axis='x', scilimits=(0, 0))
# plt.xscale('log')
ppl.plot(x, y, 'o', label='count of primes')
ppl.plot(x, delta, "--", label="Riemman function")
ppl.legend()
plt.grid()
plt.show()