Files
ad-calc/normdist.py

26 lines
798 B
Python

#!/usr/bin/env python
# From https://www.geeksforgeeks.org/python/how-to-plot-a-normal-distribution-with-matplotlib-in-python/
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
data = np.array([1, 1.1, 0.9, 1, 1, 0.9, 0.9])
lowerbound = 0.9
upperbound = 1.0
mean = data.mean()
stddev = data.std()
x = np.linspace(mean-3*stddev, mean+3*stddev, 1000)
y = norm.pdf(x, mean, stddev)
plt.plot(x, y, 'b-', label='Normal Distribution')
coloredregion = (x >= lowerbound) & ( x <= upperbound ) #select x values
plt.vlines([lowerbound, upperbound], 0, plt.ylim()[1])#ylim returns [bot, top]
plt.fill_between(x, 0, y, where=coloredregion, color="grey", alpha=0.5, label="Design Range")
plt.xlabel('X')
plt.ylabel('Probability Density')
plt.legend()
plt.grid(True)
plt.show()