#!/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 mean = 1 stddev = 5 lowerbound = -1 upperbound = 1 x = np.linspace(-10, 10 , 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()