From c343b54f0ccc3975ef04de2b143a024c9fbb1aab Mon Sep 17 00:00:00 2001 From: kp992 <145801876+kp992@users.noreply.github.com> Date: Sun, 24 Nov 2024 22:58:36 -0800 Subject: [PATCH] Remove ipywidgets from `matsuyama` lecture (#185) * Remove ipywidgets * add no-execute for widgets * Add import --------- Co-authored-by: Matt McKay --- lectures/matsuyama.md | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/lectures/matsuyama.md b/lectures/matsuyama.md index 7a22f82f..c464db57 100644 --- a/lectures/matsuyama.md +++ b/lectures/matsuyama.md @@ -3,8 +3,10 @@ jupytext: text_representation: extension: .md format_name: myst + format_version: 0.13 + jupytext_version: 1.16.4 kernelspec: - display_name: Python 3 + display_name: Python 3 (ipykernel) language: python name: python3 --- @@ -38,7 +40,7 @@ In particular, as trade costs fall and international competition increases, inno Let's start with some imports: -```{code-cell} ipython +```{code-cell} ipython3 import numpy as np import matplotlib.pyplot as plt from numba import jit @@ -335,7 +337,7 @@ These are the `@jit` statements that you see below (review [this lecture](https: Here's the main body of code -```{code-cell} python3 +```{code-cell} ipython3 @jit(nopython=True) def _hj(j, nk, s1, s2, θ, δ, ρ): """ @@ -651,9 +653,9 @@ The time series share parameters but differ in their initial condition. Here's the function -```{code-cell} python3 +```{code-cell} ipython3 def plot_timeseries(n1_0, n2_0, s1=0.5, θ=2.5, - δ=0.7, ρ=0.2, ax=None, title=''): + δ=0.7, ρ=0.2, ax=None, title=''): """ Plot a single time series with initial conditions """ @@ -735,7 +737,8 @@ Replicate the figure {ref}`shown above ` by coloring initial conditions ```{solution-start} matsuyama_ex1 :class: dropdown ``` -```{code-cell} python3 + +```{code-cell} ipython3 def plot_attraction_basis(s1=0.5, θ=2.5, δ=0.7, ρ=0.2, npts=250, ax=None): if ax is None: fig, ax = plt.subplots() @@ -790,16 +793,21 @@ in real-time. Below we use an interactive plot to do this. Note, interactive plotting requires the [ipywidgets](https://github.com/jupyter-widgets/ipywidgets) module to be installed and enabled. -```{code-cell} python3 +```{note} +This interactive plot is disabled on this static webpage. +In order to use this, we recommend to run this notebook locally. +``` + +```{code-cell} ipython3 +:class: no-execute + def interact_attraction_basis(ρ=0.2, maxiter=250, npts=250): # Create the figure and axis that we will plot on fig, ax = plt.subplots(figsize=(12, 10)) - # Create model and attraction basis s1, θ, δ = 0.5, 2.5, 0.75 model = MSGSync(s1, θ, δ, ρ) ab = model.create_attraction_basis(maxiter=maxiter, npts=npts) - # Color map with colormesh unitrange = np.linspace(0, 1, npts) cf = ax.pcolormesh(unitrange, unitrange, ab, cmap="viridis") @@ -809,11 +817,14 @@ def interact_attraction_basis(ρ=0.2, maxiter=250, npts=250): return None ``` -```{code-cell} python3 +```{code-cell} ipython3 +:class: no-execute + fig = interact(interact_attraction_basis, ρ=(0.0, 1.0, 0.05), maxiter=(50, 5000, 50), npts=(25, 750, 25)) ``` + ```{solution-end} ```