{
 "nbformat": 4,
 "nbformat_minor": 5,
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3"
  }
 },
 "cells": [
  {
   "cell_type": "code",
   "id": "cell-0",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": "# --- house style (the Press palette: accent/navy/gold/parchment) ---\nimport matplotlib as mpl\nACCENT, NAVY, GOLD, PARCH = '#7a1f1f', '#1f3a5f', '#b8860b', '#f7f2e7'\nmpl.rcParams.update({'figure.facecolor': PARCH, 'axes.facecolor': '#fffdf6',\n                     'axes.edgecolor': '#c9bfa3', 'font.family': 'serif'})\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib import animation\nfrom math import comb\n\nn = 8\nfig, ax = plt.subplots(figsize=(8, 3.5))\ndef draw(x):\n    ax.clear()\n    k = np.arange(n + 1)\n    counts = np.array([comb(n, int(ki)) for ki in k])\n    vals = counts * x**k * (1 - x)**(n - k)\n    ax.bar(k - 0.2, counts / counts.max(), width=0.4, color=NAVY,\n           label='chamber counts (normalized)')\n    ax.bar(k + 0.2, vals, width=0.4, color=ACCENT, label='chamber values')\n    ax.set(xlabel='k', title=f\"n = {n}, x = {x:.2f}:  sum of values = {vals.sum():.6f}  (Thm 7.8)\")\n    ax.legend()\n\nani = animation.FuncAnimation(fig, draw, frames=np.linspace(0.05, 0.95, 60), interval=80)\n# Colab:  from IPython.display import HTML; HTML(ani.to_jshtml())\n# Web:    ani.save('py11_chambers.gif', writer='pillow', fps=15)\nplt.show()\n"
  }
 ]
}