- python 2.7 или >=3.0
- matplotlib
Last active
April 25, 2016 14:43
-
-
Save sigorilla/a7267e7b729e6a9f61257f6474ad5ead to your computer and use it in GitHub Desktop.
Example for normal distribution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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