Skip to content

Instantly share code, notes, and snippets.

@maxdevblock
Created December 1, 2022 12:09
Show Gist options
  • Save maxdevblock/3078110801ed29e898b235fd2302941f to your computer and use it in GitHub Desktop.
Save maxdevblock/3078110801ed29e898b235fd2302941f to your computer and use it in GitHub Desktop.
import numpy as np
import scipy.stats as sps
import matplotlib.pyplot as plt
tau = 5
beta = 1/tau
d = sps.expon(scale=1/beta)
x = np.linspace(0, d.ppf(.999), 1000)
y = d.pdf(x)
P = d.cdf(15)
fig, ax = plt.subplots(facecolor="w")
plt.plot(x, y)
plt.fill_between(
x[x<=15],
0, y[x<=15],
color="r", alpha=.25
)
plt.plot([0, 0], [0, y[0]], "r")
plt.plot([15, 15], [0, y[x<=15][-1]], "r")
plt.axhline(0, color="k", alpha=.25)
plt.xlabel("Wating time $t$")
plt.ylabel("Probability Density")
plt.text(1, .01, f"$P(T\leq 15)={P*100:.0f}\%$")
plt.title(fr"$T \sim \mathrm{{Exp}}(\beta={beta})$")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment