import numpy as np
import matplotlib.pyplot as plt
y = np.arange(0, 11) ** 3
plt.plot(y, 'red')
plt.xlim([0, 10])
mean = [69, 0]
cov = [[15, 8], [8, 15]]
np.random.seed(5)
x, y = np.random.multivariate_normal(mean, cov, 2000).T
y += 180
plt.scatter(x, y, color='magenta')
plt.xlabel('Height (in)')
plt.ylabel('Weight (lbs)')
plt.title('Men\'s Height vs Weigh')
x = np.arange(0, 28651, 5730)
r = np.log(0.5)
t = 5730
y = np.exp((r / t) * x)
plt.plot(x, y)
plt.xlabel('Time (years)')
plt.ylabel('Fraction Remaining')
plt.title('Exponential Decay of C-14')
plt.yscale('log')
plt.xlim([0,28650])
x = np.arange(0, 21000, 1000)
r = np.log(0.5)
t1 = 5730
t2 = 1600
y1 = np.exp((r / t1) * x)
y2 = np.exp((r / t2) * x)
plt.plot(x, y1, 'r--', x, y2, 'green')
plt.xlabel('Time (years)')
plt.ylabel('Fraction Remaining')
plt.title('Exponential Decay of Radioactive Elements')
plt.xlim([0, 20000])
plt.ylim([0, 1])
plt.legend(['C-14', 'Ra-226'])
np.random.seed(5)
student_grades = np.random.normal(68, 15, 50)
plt.hist(student_grades, bins=10, edgecolor = "black")
plt.xlabel('Grades')
plt.ylabel('Number of Students')
plt.title('Project A')
plt.xlim([0, 100])
plt.ylim([0, 30])
y0 = np.arange(0, 11) ** 3
mean = [69, 0]
cov = [[15, 8], [8, 15]]
np.random.seed(5)
x1, y1 = np.random.multivariate_normal(mean, cov, 2000).T
y1 += 180
x2 = np.arange(0, 28651, 5730)
r2 = np.log(0.5)
t2 = 5730
y2 = np.exp((r2 / t2) * x2)
x3 = np.arange(0, 21000, 1000)
r3 = np.log(0.5)
t31 = 5730
t32 = 1600
y31 = np.exp((r3 / t31) * x3)
y32 = np.exp((r3 / t32) * x3)
np.random.seed(5)
student_grades = np.random.normal(68, 15, 50)
fig = plt.figure()
ax1 = plt.subplot2grid((3, 2), (0, 0))
ax2 = plt.subplot2grid((3, 2), (0, 1))
ax3 = plt.subplot2grid((3, 2), (1, 0))
ax4 = plt.subplot2grid((3, 2), (1, 1))
ax5 = plt.subplot2grid((3, 2), (2, 0), colspan= 2)
# Titles
plt.suptitle("All in One")
ax2.set_title('Men\'s Height vs Weigh', fontsize='x-small')
ax3.set_title('Exponential Decay of C-14', fontsize='x-small')
ax4.set_title('Exponential Decay of Radioactive Elements', fontsize='x-small')
ax5.set_title('Project A', fontsize='x-small')
# Graphs
ax1.plot(y0, 'red')
ax2.scatter(x1, y1, color='magenta')
ax3.plot(x2, y2)
ax4.plot(x3, y31, 'r--', x3, y32, 'green')
ax5.hist(student_grades, bins=10, edgecolor='black')
# Scale
ax3.set_yscale('log')
# Limits
ax1.set_xlim([0, 10])
ax3.set_xlim([0, 28650])
ax4.set_xlim([0, 20000])
ax4.set_ylim([0, 1])
ax5.set_xlim([0, 100])
ax5.set_ylim([0, 30])
# Labels
ax2.set_xlabel('Height (in)', fontsize='x-small')
ax2.set_ylabel('Weight (lbs)', fontsize='x-small')
ax3.set_xlabel('Time (years)', fontsize='x-small')
ax3.set_ylabel('Fraction Remaining', fontsize='x-small')
ax4.set_ylabel('Fraction Remaining', fontsize='x-small')
ax4.set_xlabel('Time (years)', fontsize='x-small')
ax5.set_xlabel('Grades', fontsize='x-small')
ax5.set_ylabel('Number of Students', fontsize='x-small')
# Legend
ax4.legend(['C-14', 'Ra-226'], fontsize='x-small')
fig.tight_layout()
np.random.seed(5)
fruit = np.random.randint(0, 20, (4,3))
columns = ['Farrah', 'Fred', 'Felicia']
apples = fruit[0]
bananas = fruit[1]
oranges = fruit[2]
peaches = fruit[3]
width = 0.5
fig, ax = plt.subplots()
ax.bar(columns, apples, width, label='apples', color='red')
ax.bar(columns, bananas, width, bottom=fruit[0], label='bananas', color='yellow')
ax.bar(columns, oranges, width, bottom=fruit[1] + fruit[0], label='oranges', color='#ff8000')
ax.bar(columns, peaches, width, bottom=fruit[2] + fruit[1] + fruit[0], label='peaches', color='#ffe5b4')
ax.set_ylabel('Quantity of Fruit')
ax.set_ylim([0, 80])
ax.set_title('Number of Fruit per Person')
ax.legend()
np.random.seed(5)
x = np.random.randn(2000) * 10
y = np.random.randn(2000) * 10
z = np.random.rand(2000) + 40 - np.sqrt(np.square(x) + np.square(y))
plt.scatter(x, y, c=z)
plt.xlabel('x coordinate (m)')
plt.ylabel('y coordinate (m)')
plt.title('Mountain Elevation')
colorBar = plt.colorbar()
colorBar.set_label('elevation (m)')
from mpl_toolkits.mplot3d import Axes3D
lib = np.load("pca.npz")
data = lib["data"]
labels = lib["labels"]
data_means = np.mean(data, axis=0)
norm_data = data - data_means
_, _, Vh = np.linalg.svd(norm_data)
pca_data = np.matmul(norm_data, Vh[:3].T)
fig = plt.figure(figsize=(8, 6))
ax = Axes3D(fig)
cmap = plt.get_cmap(u'plasma')
ax.scatter(pca_data[:,0], pca_data[:, 1], pca_data[:,2], c=labels, cmap=plt.get_cmap('plasma'))
ax.set_title('PCA of Iris Dataset', fontsize='20')
plt.get_cmap('plasma')