Create the appropriate graphs. Label all axes and titles.
Let’s say you’re given a choice between two ways to make money. 1: You receive $5 every day. 2: Your amount doubles every day. Model both of these as equations and then graph them. Then, create a legend where the first model is labeled “Add $5” and the second is “Double $”. The x-axis should be the days and the y-axis should be the amount of money made.
Plot two Normal distributions (histograms) with one subplot on top of the other. The first represents the heights of a sample of 50 13-year-old girls, with a mean of 59 inches and standard deviation of 3 inches. The second represents the heights of a sample of 50 13-year-old boys, with a mean of 63 inches and standard deviation of 4 inches.
Also, adjust the figure size to be 6 inches x 4 inches.
Resources:
Slides: https://docs.google.com/presentation/d/1STabsCa0odMQcYhnoUv_K2HdW17B8s1Vg4qu058wWK0/edit?usp=sharing
Code: https://replit.com/@Shrav816/IntroToPython-Class23#main.py
Contact Info:
shravyassathish@gmail.com (mentor)
kingericwu@gmail.com (TA)
felixguo41@gmail.com (TA)
1.
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1, 11)
y1 = np.array([i*5 for i in x])
y2 = np.array([2**(i-1) for i in x])
plt.plot(x, y1, label='Add 5')
plt.plot(x, y2, label='double')
plt.xlabel("Days")
plt.ylabel("Amount of money made")
plt.title("double money vs + 5 every day")
plt.show()
#1
import matplotlib.pyplot as plt
import numpy as np
def add_five(x):
return 5 * x
def double_money(x):
return 5 * (2 ** x)
x = np.arange(1, 31)
y_add_five = add_five(x)
y_double_money = double_money(x)
plt.plot(x, y_add_five, label='Add $5')
plt.plot(x, y_double_money, label='Double $')
plt.xlabel('Days')
plt.ylabel('Amount of Money')
plt.title('Comparison of Money-making Models')
plt.legend()
plt.show()
#2
import matplotlib.pyplot as plt
import numpy as np
Gavg = 59
Gstandard_dev = 3
Gheights = np.random.normal(Gavg, Gstandard_dev, 50)
Bavg = 63
Bstandard_dev = 4
Bheights = np.random.normal(Bavg, Bstandard_dev, 50)
fig, ax = plt.subplots()
fig.set_size_inches(6, 4)
ax.hist(Gheights, alpha=0.5, label='Girls')
ax.hist(Bheights, alpha=0.5, label='Boys')
ax.set_xlabel('Height (inches)')
ax.set_ylabel('Frequency')
ax.set_title('Height Distribution of 13-year-olds')
ax.legend()
plt.show()
1:
import matplotlib.pyplot as plt
import numpy as nm
x = nm.arange(1,5)
y1 = 5*x
y2 = []
cur = 5
for e in x:
y2.append(cur)
cur = 2*cur
plt.plot(x, y1)
plt.plot(x, y2)
plt.show()
2:
import matplotlib.pyplot as plt
import numpy as nm
x = nm.random.normal(59,6, 50)
plt.hist(x)
x1 = nm.random.normal(63,4, 50)
plt.hist(x1)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
a = np.arange(0, 7)
value = 1
b = np.array([])
for i in range(7):
value *= 2
b = np.append(b, np.array([value]))
plt.plot(a, a*5, label="Add $5")
plt.xlabel("Days")
plt.ylabel("$ made")
plt.plot(a, b, label="Double $")
plt.legend()
plt.show()
fig = plt.figure(figsize=(6, 4))
girlHeights = np.random.normal(59, 3, 50)
boyHeights = np.random.normal(63, 4, 50)
plt.subplot(2, 1, 1)
plt.hist(girlHeights)
plt.title("Height distribution of a sample of 50 13 year old girls")
plt.subplot(2, 1, 2)
plt.hist(boyHeights)
plt.title("Height distribution of a sample of 50 13 year old boys")
plt.show()