plotting between two limits on a gaussian

This commit is contained in:
2025-12-12 10:10:15 +00:00
parent 8e412c8f0a
commit 22768fd47b

View File

@@ -6,11 +6,19 @@ from scipy.stats import norm
mean = 1
stddev = 5
lowerbound = -1
upperbound = 1
x = np.linspace(-10, 10
, 1000)
plt.plot(x, norm.pdf(x, mean, stddev), 'b-', label='Normal Distribution')
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()