-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaying.py
More file actions
34 lines (27 loc) · 969 Bytes
/
playing.py
File metadata and controls
34 lines (27 loc) · 969 Bytes
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
import numpy as np
import matplotlib.pyplot as plt
from ksdensity import ksdensity
from pdfs import n_pdf
N = 1000
bins = 30
# Plot normal distribution
fig, ax = plt.subplots(2, sharex='col')
x = np.random.randn(1000) # randn is standard normal distribution
x_values = np.linspace(-5., 5., 100)
ks_density = ksdensity(x, width=0.4)
scale = lambda el: el * N / bins
ax[0].set_title('Histogram of normal distribution (N={})'.format(N))
ax[0].hist(x, bins=bins, density=True) # number of bins
ax[0].plot(x_values, n_pdf(x_values), linestyle='dashed')
ax[1].set_title('Smoothed curve')
ax[1].plot(x_values, ks_density(x_values))
ax[1].plot(x_values, n_pdf(x_values), linestyle='dashed')
# Plot uniform distribution
fig2, ax2 = plt.subplots(2)
x = np.random.rand(1000) # uniform distribution [0-1]
ax2[0].hist(x, bins=20)
ks_density = ksdensity(x, width=0.2)
x_values = np.linspace(-1., 2., 100)
ax2[1].plot(x_values, ks_density(x_values))
# Show plots
plt.show()