Skip to content

Commit

Permalink
Remove ipywidgets from matsuyama lecture (#185)
Browse files Browse the repository at this point in the history
* Remove ipywidgets

* add no-execute for widgets

* Add import

---------

Co-authored-by: Matt McKay <[email protected]>
  • Loading branch information
kp992 and mmcky authored Nov 25, 2024
1 parent 09fa72a commit c343b54
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions lectures/matsuyama.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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, θ, δ, ρ):
"""
Expand Down Expand Up @@ -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
"""
Expand Down Expand Up @@ -735,7 +737,8 @@ Replicate the figure {ref}`shown above <matsrep>` 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()
Expand Down Expand Up @@ -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")
Expand All @@ -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}
```

1 comment on commit c343b54

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.