2012-07-22

How to plot a normal distribution in Python


Python code (slightly adapted from StackOverflow) to plot a normal distribution.

# Plot a normal distribution


import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm


mean = 0
standard_deviation = 1


# Plot between -10 and 10 with .001 steps.
range = np.arange(-10, 10, 0.001)


# Mean = 0, SD = 1.
plt.plot(range, norm.pdf(range, mean, standard_deviation))


plt.show()

Result:



Addendum: the code above can be 
improved

No comments:

Post a Comment