Skip to content

Instantly share code, notes, and snippets.

@PatWalters
Created December 3, 2023 01:10
Show Gist options
  • Save PatWalters/d3d218646fdb21292e5ceffc5d9a54a4 to your computer and use it in GitHub Desktop.
Save PatWalters/d3d218646fdb21292e5ceffc5d9a54a4 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 66,
"id": "e793e033",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import seaborn as sns\n",
"import scipy\n",
"from ipywidgets import interact\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 72,
"id": "56bbdedb",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1cd7884fb56841058861214014fb5529",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(IntSlider(value=0, description='skew', max=5, min=-5), FloatSlider(value=3.0, descriptio…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"@interact(skew=(-5, 5),mean=(1,5,0.25))\n",
"def f(skew,mean):\n",
" fig, axes = plt.subplots(2,1)\n",
" ax0, ax1 = axes\n",
" xlims = (0,8)\n",
" ylims = (0,1)\n",
" \n",
" d0 = scipy.stats.skewnorm(skew, mean, 1).rvs(10000) \n",
" sns.kdeplot(d0, ax=ax0)\n",
" ax0.set_xlim(*xlims)\n",
" ax0.set_ylim(*ylims)\n",
" ax0.set_title(\"Stage 1\")\n",
" \n",
" # sample d0 to get d1 \n",
" s0 = np.random.choice(d0,500) - 1.0\n",
" stage2_mean = np.mean(s0)+2\n",
" d1 = np.random.normal(stage2_mean,1,500)\n",
" \n",
" sns.kdeplot(d1,ax=ax1)\n",
" ax1.set_xlim(*xlims)\n",
" ax1.set_ylim(*ylims)\n",
" ax1.set_title(\"Stage 2\")\n",
" plt.tight_layout()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "52660154",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment