Skip to content

Instantly share code, notes, and snippets.

@sigorilla
Last active April 25, 2016 14:43
Show Gist options
  • Save sigorilla/a7267e7b729e6a9f61257f6474ad5ead to your computer and use it in GitHub Desktop.
Save sigorilla/a7267e7b729e6a9f61257f6474ad5ead to your computer and use it in GitHub Desktop.
Example for normal distribution

Зависимости

  • python 2.7 или >=3.0
  • matplotlib

Результат данного скрипта

gauss

from matplotlib import pyplot as plt
from matplotlib import mlab
from random import seed, gauss
SEED = 20
MU = 0
SIGMA = 1
RANGE = 10000
# Count of bars on the histogram.
NUM_BINS = 100
def main():
# Initialize the random number generator.
# If a is omitted or None, the current system time is used.
seed(a=20)
# Using gauss function to generate normal distribution.
x = [gauss(MU, SIGMA) for _ in range(RANGE)]
# The histogram of the data.
n, bins, patches = plt.hist(x, NUM_BINS, normed=1, facecolor='green', alpha=0.5)
# Add a 'best fit' line.
y = mlab.normpdf(bins, MU, SIGMA)
plt.plot(bins, y, 'r--')
# Labels.
plt.xlabel('Values')
plt.ylabel('Probability')
plt.title('Gaussian')
# Tweak spacing to prevent clipping of ylabel.
plt.subplots_adjust(left=0.15)
plt.show()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment