diff --git a/lectures/ar1_processes.md b/lectures/ar1_processes.md index fe54d3d1..34b93ae7 100644 --- a/lectures/ar1_processes.md +++ b/lectures/ar1_processes.md @@ -180,7 +180,7 @@ for t in range(sim_length): mu = a * mu + b v = a**2 * v + c**2 ax.plot(grid, norm.pdf(grid, loc=mu, scale=np.sqrt(v)), - label=f"$\psi_{t}$", + label=fr"$\psi_{t}$", alpha=0.7) ax.legend(bbox_to_anchor=[1.05,1],loc=2,borderaxespad=1) @@ -267,7 +267,7 @@ plot_density_seq(ax, mu_0=4.0) mu_star = b / (1 - a) std_star = np.sqrt(c**2 / (1 - a**2)) # square root of v_star psi_star = norm.pdf(grid, loc=mu_star, scale=std_star) -ax.plot(grid, psi_star, 'k-', lw=2, label="$\psi^*$") +ax.plot(grid, psi_star, 'k-', lw=2, label=r"$\psi^*$") ax.legend() plt.show() diff --git a/lectures/cobweb.md b/lectures/cobweb.md index 31d71812..3bda73f9 100644 --- a/lectures/cobweb.md +++ b/lectures/cobweb.md @@ -271,7 +271,7 @@ def plot45(model, pmin, pmax, p0, num_arrows=5): ax.plot(pgrid, g(model, pgrid), 'b-', lw=2, alpha=0.6, label='g') - ax.plot(pgrid, pgrid, lw=1, alpha=0.7, label='$45\degree$') + ax.plot(pgrid, pgrid, lw=1, alpha=0.7, label=r'$45\degree$') x = p0 xticks = [pmin] diff --git a/lectures/eigen_I.md b/lectures/eigen_I.md index 948b2f05..9cd68352 100644 --- a/lectures/eigen_I.md +++ b/lectures/eigen_I.md @@ -265,7 +265,7 @@ def circle_transform(A=np.array([[-1, 2], [0, 1]])): ax[0].plot(x, y, color='black', zorder=1) ax[0].scatter(a_1, b_1, c=colors, alpha=1, s=60, edgecolors='black', zorder=2) - ax[0].set_title("unit circle in $\mathbb{R}^2$") + ax[0].set_title(r"unit circle in $\mathbb{R}^2$") x1 = x.reshape(1, -1) y1 = y.reshape(1, -1) @@ -542,15 +542,15 @@ def grid_composition_transform(A=np.array([[1, -1], [1, 1]]), # Plot grid points ax[0].scatter(xygrid[0], xygrid[1], s=36, c=colors, edgecolor="none") - ax[0].set_title("points $x_1, x_2, \cdots, x_k$") + ax[0].set_title(r"points $x_1, x_2, \cdots, x_k$") # Plot intermediate grid points ax[1].scatter(uvgrid[0], uvgrid[1], s=36, c=colors, edgecolor="none") - ax[1].set_title("points $Bx_1, Bx_2, \cdots, Bx_k$") + ax[1].set_title(r"points $Bx_1, Bx_2, \cdots, Bx_k$") # Plot transformed grid points ax[2].scatter(abgrid[0], abgrid[1], s=36, c=colors, edgecolor="none") - ax[2].set_title("points $ABx_1, ABx_2, \cdots, ABx_k$") + ax[2].set_title(r"points $ABx_1, ABx_2, \cdots, ABx_k$") plt.show() ``` diff --git a/lectures/equalizing_difference.md b/lectures/equalizing_difference.md index c65bbf9a..95a6635f 100644 --- a/lectures/equalizing_difference.md +++ b/lectures/equalizing_difference.md @@ -374,7 +374,7 @@ We'll use the Python module 'sympy' to compute partial derivatives of $\phi$ wit Define symbols ```{code-cell} ipython3 -γ_h, γ_c, w_h0, D = symbols('\gamma_h, \gamma_c, w_0^h, D', real=True) +γ_h, γ_c, w_h0, D = symbols(r'\gamma_h, \gamma_c, w_0^h, D', real=True) R, T = Symbol('R', real=True), Symbol('T', integer=True) ``` diff --git a/lectures/geom_series.md b/lectures/geom_series.md index 0ea97279..e33ed5c4 100644 --- a/lectures/geom_series.md +++ b/lectures/geom_series.md @@ -761,7 +761,7 @@ T_max = 10 T=np.arange(0, T_max+1) rs, gs = (0.9, 0.5, 0.4001, 0.4), (0.4, 0.4, 0.4, 0.5), -comparisons = ('$\gg$', '$>$', r'$\approx$', '$<$') +comparisons = (r'$\gg$', '$>$', r'$\approx$', '$<$') for r, g, comp in zip(rs, gs, comparisons): ax.plot(finite_lease_pv_true(T, g, r, x_0), label=f'r(={r}) {comp} g(={g})') diff --git a/lectures/greek_square.md b/lectures/greek_square.md index 8bf4a982..9c6a532d 100644 --- a/lectures/greek_square.md +++ b/lectures/greek_square.md @@ -693,7 +693,7 @@ fig, axs = plt.subplots(1, 2, figsize=(12, 6), dpi=500) axs[0].plot(np.round(ratios_λ1, 6), label=r'$\frac{y_t}{y_{t-1}}$', linewidth=3) axs[0].axhline(y=Λ[1], color='red', linestyle='--', - label='$\lambda_2$', alpha=0.5) + label=r'$\lambda_2$', alpha=0.5) axs[0].set_xlabel('t', size=18) axs[0].set_ylabel(r'$\frac{y_t}{y_{t-1}}$', size=18) axs[0].set_title(r'$\frac{y_t}{y_{t-1}}$ after Muting $\lambda_1$', @@ -704,7 +704,7 @@ axs[0].legend() axs[1].plot(ratios_λ2, label=r'$\frac{y_t}{y_{t-1}}$', linewidth=3) axs[1].axhline(y=Λ[0], color='green', linestyle='--', - label='$\lambda_1$', alpha=0.5) + label=r'$\lambda_1$', alpha=0.5) axs[1].set_xlabel('t', size=18) axs[1].set_ylabel(r'$\frac{y_t}{y_{t-1}}$', size=18) axs[1].set_title(r'$\frac{y_t}{y_{t-1}}$ after Muting $\lambda_2$', diff --git a/lectures/heavy_tails.md b/lectures/heavy_tails.md index 854a7597..15f2970e 100644 --- a/lectures/heavy_tails.md +++ b/lectures/heavy_tails.md @@ -361,7 +361,7 @@ for ax, s in zip(axes[:2], s_vals): data = np.random.randn(n) * s ax.plot(list(range(n)), data, linestyle='', marker='o', alpha=0.5, ms=4) ax.vlines(list(range(n)), 0, data, lw=0.2) - ax.set_title(f"draws from $N(0, \sigma^2)$ with $\sigma = {s}$", fontsize=11) + ax.set_title(fr"draws from $N(0, \sigma^2)$ with $\sigma = {s}$", fontsize=11) ax = axes[2] distribution = cauchy() diff --git a/lectures/inequality.md b/lectures/inequality.md index b1ec0e11..f87645a7 100644 --- a/lectures/inequality.md +++ b/lectures/inequality.md @@ -522,7 +522,7 @@ mystnb: fix, ax = plot_inequality_measures(σ_vals, ginis, 'simulated', - '$\sigma$', + r'$\sigma$', 'Gini coefficients') plt.show() ``` @@ -888,7 +888,7 @@ ax.plot(years, df_topshares["topshare_n_wealth"], ax.plot(years, df_topshares["topshare_t_income"], marker='o', label="total income") ax.set_xlabel("year") -ax.set_ylabel("top $10\%$ share") +ax.set_ylabel(r"top $10\%$ share") ax.legend() plt.show() ``` diff --git a/lectures/input_output.md b/lectures/input_output.md index 7c8170c2..6c768cea 100644 --- a/lectures/input_output.md +++ b/lectures/input_output.md @@ -210,9 +210,9 @@ ax.plot(np.linspace(55, 380, 100), (50-0.9*np.linspace(55, 380, 100))/(-1.46), c ax.plot(np.linspace(-1, 400, 100), (60+0.16*np.linspace(-1, 400, 100))/0.83, color="r") ax.plot(np.linspace(250, 395, 100), (62-0.04*np.linspace(250, 395, 100))/0.33, color="b") -ax.text(130, 38, "$(1-a_{11})x_1 + a_{12}x_2 \geq d_1$", size=10) -ax.text(10, 105, "$-a_{21}x_1 + (1-a_{22})x_2 \geq d_2$", size=10) -ax.text(150, 150, "$a_{01}x_1 +a_{02}x_2 \leq x_0$", size=10) +ax.text(130, 38, r"$(1-a_{11})x_1 + a_{12}x_2 \geq d_1$", size=10) +ax.text(10, 105, r"$-a_{21}x_1 + (1-a_{22})x_2 \geq d_2$", size=10) +ax.text(150, 150, r"$a_{01}x_1 +a_{02}x_2 \leq x_0$", size=10) # Draw the feasible region feasible_set = Polygon(np.array([[301, 151], @@ -466,8 +466,8 @@ ax.vlines(0, -1, 250) ax.plot(np.linspace(4.75, 49, 100), (4-0.9*np.linspace(4.75, 49, 100))/(-0.16), color="r") ax.plot(np.linspace(0, 50, 100), (33+1.46*np.linspace(0, 50, 100))/0.83, color="r") -ax.text(15, 175, "$(1-a_{11})p_1 - a_{21}p_2 \leq a_{01}w$", size=10) -ax.text(30, 85, "$-a_{12}p_1 + (1-a_{22})p_2 \leq a_{02}w$", size=10) +ax.text(15, 175, r"$(1-a_{11})p_1 - a_{21}p_2 \leq a_{01}w$", size=10) +ax.text(30, 85, r"$-a_{12}p_1 + (1-a_{22})p_2 \leq a_{02}w$", size=10) # Draw the feasible region feasible_set = Polygon(np.array([[17, 69], diff --git a/lectures/intro_supply_demand.md b/lectures/intro_supply_demand.md index aea36eb5..575a4ccc 100644 --- a/lectures/intro_supply_demand.md +++ b/lectures/intro_supply_demand.md @@ -348,7 +348,7 @@ ab_grid = np.linspace(a, b, 400) fig, ax = plt.subplots() ax.plot(x_grid, f(x_grid), label="$f$", color="k") ax.fill_between(ab_grid, [0] * len(ab_grid), f(ab_grid), - label="$\int_a^b f(x) dx$") + label=r"$\int_a^b f(x) dx$") ax.legend() plt.show() ``` diff --git a/lectures/laffer_adaptive.md b/lectures/laffer_adaptive.md index 684f2e6f..b91240d9 100644 --- a/lectures/laffer_adaptive.md +++ b/lectures/laffer_adaptive.md @@ -379,15 +379,15 @@ def draw_iterations(π0s, model, line_params, π_bars, num_steps): axes[2].axhline(y=π_bars[0], color='grey', linestyle='--', lw=1.5, alpha=0.6) axes[2].axhline(y=π_bars[1], color='grey', linestyle='--', lw=1.5, alpha=0.6) - axes[2].text(num_steps * 1.07, π_bars[0], '$\pi_l$', verticalalignment='center', + axes[2].text(num_steps * 1.07, π_bars[0], r'$\pi_l$', verticalalignment='center', color='grey', size=10) - axes[2].text(num_steps * 1.07, π_bars[1], '$\pi_u$', verticalalignment='center', + axes[2].text(num_steps * 1.07, π_bars[1], r'$\pi_u$', verticalalignment='center', color='grey', size=10) axes[0].set_ylabel('$m_t$') axes[1].set_ylabel('$p_t$') - axes[2].set_ylabel('$\pi_t$') - axes[3].set_ylabel('$\mu_t$') + axes[2].set_ylabel(r'$\pi_t$') + axes[3].set_ylabel(r'$\mu_t$') axes[3].set_xlabel('timestep') axes[3].xaxis.set_major_locator(MaxNLocator(integer=True)) diff --git a/lectures/lln_clt.md b/lectures/lln_clt.md index 83f21d43..476a5548 100644 --- a/lectures/lln_clt.md +++ b/lectures/lln_clt.md @@ -491,7 +491,7 @@ ax.set_xlim(xmin, xmax) ax.hist(Y, bins=60, alpha=0.4, density=True) xgrid = np.linspace(xmin, xmax, 200) ax.plot(xgrid, st.norm.pdf(xgrid, scale=σ), - 'k-', lw=2, label='$N(0, \sigma^2)$') + 'k-', lw=2, label=r'$N(0, \sigma^2)$') ax.set_xlabel(r"$Y_n$", size=12) ax.set_ylabel(r"$density$", size=12) @@ -543,7 +543,7 @@ ax.hist(Y, bins=60, alpha=0.4, density=True) ax.set_xlabel(r"$Y_n$", size=12) ax.set_ylabel(r"$density$", size=12) xgrid = np.linspace(xmin, xmax, 200) -ax.plot(xgrid, st.norm.pdf(xgrid, scale=σ), 'k-', lw=2, label='$N(0, \sigma^2)$') +ax.plot(xgrid, st.norm.pdf(xgrid, scale=σ), 'k-', lw=2, label=r'$N(0, \sigma^2)$') ax.legend() plt.show() diff --git a/lectures/markov_chains_II.md b/lectures/markov_chains_II.md index a6237d7c..25996829 100644 --- a/lectures/markov_chains_II.md +++ b/lectures/markov_chains_II.md @@ -328,7 +328,7 @@ for i in range(n): # Generate time series starting at different x_0 X = mc.simulate(ts_length, init=x0) p_hat = (X == i).cumsum() / np.arange(1, ts_length+1) - axes[i].plot(p_hat, label=f'$x_0 = \, {x0} $') + axes[i].plot(p_hat, label=fr'$x_0 = \, {x0} $') axes[i].legend() plt.tight_layout() diff --git a/lectures/money_inflation_nonlinear.md b/lectures/money_inflation_nonlinear.md index 07922373..bce94f09 100644 --- a/lectures/money_inflation_nonlinear.md +++ b/lectures/money_inflation_nonlinear.md @@ -187,14 +187,14 @@ def plot_laffer(model, πs): # Plot the function plt.plot(x_values, y_values, label=f'Laffer curve') - for π, label in zip(πs, ['$\pi_l$', '$\pi_u$']): + for π, label in zip(πs, [r'$\pi_l$', r'$\pi_u$']): plt.text(π, plt.gca().get_ylim()[0]*2, label, horizontalalignment='center', color='brown', size=10) plt.axvline(π, color='brown', linestyle='--') plt.axhline(g, color='red', linewidth=0.5, linestyle='--', label='g') - plt.xlabel('$\pi$') + plt.xlabel(r'$\pi$') plt.ylabel('seigniorage') plt.legend() plt.show() @@ -373,8 +373,8 @@ def draw_iterations(p0s, model, line_params, p0_bars, num_steps): # Draw labels axes[0].set_ylabel('$m_t$') axes[1].set_ylabel('$p_t$') - axes[2].set_ylabel('$\pi_t$') - axes[3].set_ylabel('$\mu_t$') + axes[2].set_ylabel(r'$\pi_t$') + axes[3].set_ylabel(r'$\mu_t$') axes[3].set_xlabel('timestep') for p_0, label in [(p0_bars[0], '$p_0=p_l$'), (p0_bars[1], '$p_0=p_u$')]: diff --git a/lectures/olg.md b/lectures/olg.md index 6530e1be..0794b2ce 100644 --- a/lectures/olg.md +++ b/lectures/olg.md @@ -446,7 +446,7 @@ fig, ax = plt.subplots(figsize=(6, 6)) ymin, ymax = np.min(k_grid_next), np.max(k_grid_next) ax.plot(k_grid, k_grid_next, lw=2, alpha=0.6, label='$g$') -ax.plot(k_grid, k_grid, 'k-', lw=1, alpha=0.7, label='$45^{\circ}$') +ax.plot(k_grid, k_grid, 'k-', lw=1, alpha=0.7, label=r'$45^{\circ}$') ax.legend(loc='upper left', frameon=False, fontsize=12) @@ -722,7 +722,7 @@ fig, ax = plt.subplots(figsize=(6, 6)) ymin, ymax = np.min(k_grid_next), np.max(k_grid_next) ax.plot(k_grid, k_grid_next, lw=2, alpha=0.6, label='$g$') -ax.plot(k_grid, k_grid, 'k-', lw=1, alpha=0.7, label='$45^{\circ}$') +ax.plot(k_grid, k_grid, 'k-', lw=1, alpha=0.7, label=r'$45^{\circ}$') ax.legend(loc='upper left', frameon=False, fontsize=12) diff --git a/lectures/prob_dist.md b/lectures/prob_dist.md index 4760053a..9889b919 100644 --- a/lectures/prob_dist.md +++ b/lectures/prob_dist.md @@ -496,7 +496,7 @@ for μ, σ in zip(μ_vals, σ_vals): u = scipy.stats.lognorm(σ, scale=np.exp(μ)) ax.plot(x_grid, u.pdf(x_grid), alpha=0.5, lw=2, - label=f'$\mu={μ}, \sigma={σ}$') + label=fr'$\mu={μ}, \sigma={σ}$') ax.set_xlabel('x') ax.set_ylabel('PDF') plt.legend() diff --git a/lectures/solow.md b/lectures/solow.md index 0a5160b0..ee02b8be 100644 --- a/lectures/solow.md +++ b/lectures/solow.md @@ -146,7 +146,7 @@ def plot45(kstar=None): lb = r'$g(k) = sAk^{\alpha} + (1 - \delta)k$' ax.plot(xgrid, g_values, lw=2, alpha=0.6, label=lb) - ax.plot(xgrid, xgrid, 'k-', lw=1, alpha=0.7, label='$45^{\circ}$') + ax.plot(xgrid, xgrid, 'k-', lw=1, alpha=0.7, label=r'$45^{\circ}$') if kstar: fps = (kstar,) diff --git a/lectures/unpleasant.md b/lectures/unpleasant.md index 5eb80e31..0891036c 100644 --- a/lectures/unpleasant.md +++ b/lectures/unpleasant.md @@ -481,7 +481,7 @@ def plot_path(m0_arr, model, length=15): ax.set_title(titles[i]) axs[0, 1].hlines(model.m0_check, 0, length, color='r', linestyle='--') - axs[0, 1].text(length * 0.8, model.m0_check * 0.9, '$\check{m}_0$') + axs[0, 1].text(length * 0.8, model.m0_check * 0.9, r'$\check{m}_0$') plt.show() ```