Skip to content

Instantly share code, notes, and snippets.

@RahulDas-dev
Last active September 16, 2024 13:15
Show Gist options
  • Save RahulDas-dev/7d73766f173830bf6f846133a267a789 to your computer and use it in GitHub Desktop.
Save RahulDas-dev/7d73766f173830bf6f846133a267a789 to your computer and use it in GitHub Desktop.
Plot Samples from Gaussian distributations
import numpy as np
import seaborn as sns
from matplotlib import pyplot as plt
from matplotlib.offsetbox import AnchoredText
from scipy import stats
from ipywidgets import interact
sns.set(style='darkgrid', context='talk', )
sns.set_theme()
def plot_func(n_samples):
mean = 0
std = 12
gaussian = stats.norm(mean, std)
xs = np.linspace(*gaussian.ppf([0.001, 0.999]), 2000)
ys = gaussian.pdf(xs)
sample = np.random.normal(mean, std, n_samples)
ax = plt.gca()
_ = sns.lineplot(x=xs,y=ys, ax=ax, color='black')
_ = sns.histplot(data=sample,stat='probability', color= 'pink', discrete =True, ax=ax)
anc = AnchoredText(f"n_samples {n_samples}", loc="upper left", frameon=False)
ax.add_artist(anc)
interact(plot_func, n_samples = (20,10000, 50))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment