@@ -3,8 +3,10 @@ jupytext:
33 text_representation :
44 extension : .md
55 format_name : myst
6+ format_version : 0.13
7+ jupytext_version : 1.16.4
68kernelspec :
7- display_name : Python 3
9+ display_name : Python 3 (ipykernel)
810 language : python
911 name : python3
1012---
@@ -38,11 +40,10 @@ In particular, as trade costs fall and international competition increases, inno
3840
3941Let's start with some imports:
4042
41- ``` {code-cell} ipython
43+ ``` {code-cell} ipython3
4244import numpy as np
4345import matplotlib.pyplot as plt
4446from numba import jit
45- from ipywidgets import interact
4647```
4748
4849### Background
@@ -335,7 +336,7 @@ These are the `@jit` statements that you see below (review [this lecture](https:
335336
336337Here's the main body of code
337338
338- ``` {code-cell} python3
339+ ``` {code-cell} ipython3
339340@jit(nopython=True)
340341def _hj(j, nk, s1, s2, θ, δ, ρ):
341342 """
@@ -651,9 +652,9 @@ The time series share parameters but differ in their initial condition.
651652
652653Here's the function
653654
654- ``` {code-cell} python3
655+ ``` {code-cell} ipython3
655656def plot_timeseries(n1_0, n2_0, s1=0.5, θ=2.5,
656- δ=0.7, ρ=0.2, ax=None, title=''):
657+ δ=0.7, ρ=0.2, ax=None, title=''):
657658 """
658659 Plot a single time series with initial conditions
659660 """
@@ -735,7 +736,8 @@ Replicate the figure {ref}`shown above <matsrep>` by coloring initial conditions
735736``` {solution-start} matsuyama_ex1
736737:class: dropdown
737738```
738- ``` {code-cell} python3
739+
740+ ``` {code-cell} ipython3
739741def plot_attraction_basis(s1=0.5, θ=2.5, δ=0.7, ρ=0.2, npts=250, ax=None):
740742 if ax is None:
741743 fig, ax = plt.subplots()
@@ -784,36 +786,5 @@ fig.suptitle("Synchronized versus Asynchronized 2-cycles",
784786plt.show()
785787```
786788
787- Additionally, instead of just seeing 4 plots at once, we might want to
788- manually be able to change $\rho$ and see how it affects the plot
789- in real-time. Below we use an interactive plot to do this.
790-
791- Note, interactive plotting requires the [ ipywidgets] ( https://github.com/jupyter-widgets/ipywidgets ) module to be installed and enabled.
792-
793- ``` {code-cell} python3
794- def interact_attraction_basis(ρ=0.2, maxiter=250, npts=250):
795- # Create the figure and axis that we will plot on
796- fig, ax = plt.subplots(figsize=(12, 10))
797-
798- # Create model and attraction basis
799- s1, θ, δ = 0.5, 2.5, 0.75
800- model = MSGSync(s1, θ, δ, ρ)
801- ab = model.create_attraction_basis(maxiter=maxiter, npts=npts)
802-
803- # Color map with colormesh
804- unitrange = np.linspace(0, 1, npts)
805- cf = ax.pcolormesh(unitrange, unitrange, ab, cmap="viridis")
806- cbar_ax = fig.add_axes([0.95, 0.15, 0.05, 0.7])
807- plt.colorbar(cf, cax=cbar_ax)
808- plt.show()
809- return None
810- ```
811-
812- ``` {code-cell} python3
813- fig = interact(interact_attraction_basis,
814- ρ=(0.0, 1.0, 0.05),
815- maxiter=(50, 5000, 50),
816- npts=(25, 750, 25))
817- ```
818789``` {solution-end}
819790```
0 commit comments