Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion generate_data.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import numpy as np
import matplotlib.pyplot as plt

# Fixing random state for reproducibility
np.random.seed(19680801)

mu, sigma = 100, 15
x_gaussian = mu + sigma * np.random.randn(10000)

np.savetxt('file_data.csv', x_gaussian, delimiter=',')
mu, sigma = 100, 5
x_chisqrd = mu + sigma * (np.random.randm(10,10000)**2).sum(0)






np.savetxt('file_data_gaussian.csv', x_gaussian, delimiter=',')
np.savetxt('file_data_chisqrd.csv', x_chisqrd, delimiter=',')
24 changes: 13 additions & 11 deletions plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
import matplotlib.pyplot as plt

# Data are loaded from a file
x = np.loadtxt('file_data.csv')

gaussian = np.loadtxt('file_data_gaussian.csv')
chisqrd = np.loadtxt('file_data_chisqrd.csv')
# the histogram of the data
n, bins, patches = plt.hist(x, 50, density=True, facecolor='r, alpha=0.74)
n, bins, patches = plt.hist(gaussian, 50, density=True, facecolor='r', alpha=0.74)
n, bins, patches = plt.hist(chisqrd, 50, density=True, facecolor='b', alpha=0.25)

plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title('Histogram of IQ')
plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
plt.xlim(40, 160)
plt.ylim(0, 0.03)
plt.grid(True)
plt.show()
plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title('Histogram of IQ')
plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
plt.text(80, .020, r'$\mu=100,\ \sigma=5$')
plt.xlim(40, 250)
plt.ylim(0, 0.03)
plt.grid(True)
plt.show()