Question: Write a python program that demonstrates your knowledge of the following topics. How to plot histograms using matplotlib How to populate a figure using matplotlib

Write a python program that demonstrates your knowledge of the following topics.
How to plot histograms using matplotlib
How to populate a figure using matplotlib
How to decorate a figure using matplotlib
How to find the mean and standard deviation of a dataset
How to create a normal distribution curve for a given mean and standard deviation
How to overlay a normal distribution curve on a histogram
Write and submit a Python module named Proj04Runner.py that works in conjunction with the driver source code contained in the file named Proj04.py
The program must terminate and return control to the operating system when the user dismisses the image by clicking the X-button on the image window.
You may not modify the code in the file named Proj04.py for the purpose of meeting this specification. The normed parameter has been removed from the hist method in later versions of pyplot. Don't use "normed=True". Use "density=True" instead.
Here is Proj04.py:
from Proj04Runner import Runner
import sys
import random
#Define a utility function that will be used later to create
#several datasets.
def normalRandomGenerator(seed=1,dataLength=10000,numberSamples=50,\
lowLim=0,highLim=100):
'''
Create a new dataset of dataLength values consisting of the
average of numberSamples samples taken from a population of
uniformly distributed values between lowLim and highLim
generated with a seed of seed.
Input keyword parameters and their default values:
seed =1 seed used to generate the uniformly distributed values
dataLength =10000 number of samples in the returned list of values
numberSamples =50 number of samples taken from the uniformly
distributed population and averaged into the output
lowLim =0 lower limit value of the uniformly distributed population
highLim =100 high limit value of the uniformly distributed population
returns: a list containing the dataset
'''
data =[]
random.seed(seed)
for cnt in range(dataLength):
theSum =0
for cnt1 in range(numberSamples):
theSum += random.uniform(lowLim,highLim)
data.append(theSum/numberSamples)
return data
#=========================================================================#
#Populate variables that will be used to create four datasets.
xSeed =1
xDataLength =5000
xNumberSamples =1
xLowLim =600
xHighLim =1000
print("
xSeed =",xSeed)
print("xDataLength =",xDataLength)
print('xNumberSamples =',xNumberSamples)
print('xLowLim =',xLowLim)
print('xHighLim =',xHighLim)
print()
#Create four datasets
data01= normalRandomGenerator(seed=xSeed,dataLength=xDataLength,\
numberSamples=xNumberSamples,\
lowLim=xLowLim,\
highLim=xHighLim\
)
data02= normalRandomGenerator(seed=xSeed,dataLength=xDataLength,\
numberSamples =2*xNumberSamples,\
lowLim=xLowLim,\
highLim=xHighLim\
)
data03= normalRandomGenerator(seed=xSeed,dataLength=xDataLength,\
numberSamples =4*xNumberSamples,\
lowLim=xLowLim,\
highLim=xHighLim\
)
data04= normalRandomGenerator(seed=xSeed,dataLength=xDataLength,\
numberSamples =8*xNumberSamples,\
lowLim=xLowLim,\
highLim=xHighLim\
)
print("Output from student code begins here.")
#Call the student's run method in the class named Runner in the
#file named Proj04Runner.py, passing four datasets as parameters.
Runner.run(data01,data02,data03,data04)
#-----end of proj04 program----
My questions is, is my runner file okay?
Here is my Proj04Runner.py file:
import matplotlib.pyplot as plt
import numpy as np
class Runner:
@staticmethod
def run(data01, data02, data03, data04):
# Create histograms for each dataset
plt.figure(figsize=(10,6))
plt.hist(data01, bins=50, density=True, alpha=0.5, label='Dataset 01')
plt.hist(data02, bins=50, density=True, alpha=0.5, label='Dataset 02')
plt.hist(data03, bins=50, density=True, alpha=0.5, label='Dataset 03')
plt.hist(data04, bins=50, density=True, alpha=0.5, label='Dataset 04')
# Calculate mean and standard deviation for each dataset
mean01, std01= np.mean(data01), np.std(data01)
mean02, std02= np.mean(data02), np.std(data02)
mean03, std03= np.mean(data03), np.std(data03)
mean04, std04= np.mean(data04), np.std(data04)
# Plot normal distribution curves
x = np.linspace(min(data01+ data02+ data03+ data04), max(data01+ data02+ data03+ data04),100)
plt.plot(x,(1/(std01* np.sqrt(2* np.pi)))* np.exp(-0.5*((x - mean01)/ std01)**2), label='Normal Dist. 01')
plt.plot(x,(1/(std02* np.sqrt(2* np.pi)))* np.exp(-0.5*((x - mean02)/ std02)**2), label='Normal Dist. 02')
plt.plot(x,(1/(std03* np.sqrt(2* np.pi)))* np.exp(-

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!