Solution
Solution
class normalPlotter:
def __init__(self,dist):
self.dist = dist
def plot(self,xPoint,end,zScore = False):
xVals = list(range(end+1))
yVals = [self.dist.pdf(x) for x in xVals]
xVals2 = list(range(xPoint+1))
yVals2 = [self.dist.pdf(x) for x in xVals2]
if zScore:
xVals = [(x-self.dist.mean())/self.dist.std() for x in xVals]
xVals2 = [(x-self.dist.mean())/self.dist.std() for x in xVals2]
plt.plot(xVals,yVals)
if zScore:
plt.xlabel("Z Score")
else:
plt.xlabel("Value")
plt.ylabel("Density")
plt.fill_between(xVals2, yVals2)
plt.show()
xVals = list(range(end+1))
yVals = [self.dist.cdf(x) for x in xVals]
if zScore:
xVals = [(x-self.dist.mean())/self.dist.std() for x in xVals]
plt.plot(xVals,yVals)
plt.xlabel("Z Score")
plt.ylabel("Cummulative Percentage")
if zScore:
plt.xlabel("Z Score")
plt.plot((xPoint-self.dist.mean())/self.dist.std(),dist.cdf(xPoint),"ro")
else:
plt.xlabel("Value")
plt.plot(xPoint,dist.cdf(xPoint),"ro")
plt.show()
x = normalPlotter(scipy.stats.norm(400,100))
x.plot(350,800)
x.plot(350,800,zScore=True)
The only new thing here may be how we use zScore = False in the plot function. This sets up an optional parameter, it is by default false, but the user could change it to true.
Source Code