plt.subplot(3,1,1)
x1 = np.random.randn(1000) 



The function randn(N) produces an array of N elements . The elements are distributed according to
P(x) = \frac{1}{\sqrt{2 \pi}} e^{\frac{-(x)^2}{2}}
This is the normal distribution you plotted in lab07 with a mean of zero and a sigma of 1.

If we want a random numbers with a Gaussian distribution of width σ centered about μ.




plt.subplot(3,1,2)
mu , sigma = 5,10 
x2= sigma* np.random.randn(1000) + mu



To display the content of x1 and x2 we store and plot them in a histogram. A histogram can be thought of as a set of bins. Each element of an array (x1 or x2 ) is entered into one and only one of these bins.




plt.hist(x1,bins=100,range=(-5.0,5.0),histtype='step',color='black')




Here you are plotting a histogram using matplotlib function hist .
Note: the options used here are one positional argument and the rest are Keyword arguments . The options are:
  • The positional argument x1. Where x1 is the array we would like to histogram
  • the number of bins in the histogram
  • the range of the histogram bins. In here we are plotting from -5 to 5.
  • the drawing option for type of histogram histype.
  • histogram color




    n2,b2,p2 = plt.hist(x1,bins=10,range=(-5.0,5.0),histtype='step',color='black')
    



    Here we assigned return values of hist to be n2,b2,p2. n2 and b2 are often useful. Add some print statements and see if you can figure out what they are.




    n3,b3,p3 = plt.hist(x2,bins=10,range=(-30.0,30.0),histtype='step',color='black')
    n4,b4,p4 =plt.hist(x2,bins=100,range=(-30.0,30.0),histtype='step',color='black')
    



    Here you are plotting the same histogram with different number of bins. What is the affect of increasing the number of bins?