From 35f50ccdcc7567f8c5bd64b83757610f782b419e Mon Sep 17 00:00:00 2001 From: Jesse Perla Date: Wed, 20 Nov 2024 08:26:45 -0800 Subject: [PATCH] Graph fixes (#317) * Fixed plot titles * Missing bands --- .../additive_functionals.md | 36 +++++++++---------- .../multiplicative_functionals.md | 11 +++--- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/lectures/time_series_models/additive_functionals.md b/lectures/time_series_models/additive_functionals.md index aa3963c9..4c729e3d 100644 --- a/lectures/time_series_models/additive_functionals.md +++ b/lectures/time_series_models/additive_functionals.md @@ -566,7 +566,8 @@ function plot_martingales(amf, T, npaths = 25) plot_martingale_paths(T, mpath_mult[(li + 1):ui, :], mbounds_mult[(LI + 1):UI, :], horline = 1)) plot!(mart_figs[ii + 1], - title = L"Martingale components for many paths of $y_{ii + 1}$") + title = L"Martingale components for many paths of $y_{ii + 1}$", + titlefontsize = 12) end return mart_figs @@ -594,7 +595,8 @@ function plot_given_paths(T, ypath, mpath, spath, tpath, mbounds, sbounds; end plot!(plots[1], seriestype = :hline, [horline], color = :black, linestyle = :dash, label = "") - plot!(plots[1], title = "One Path of All Variables", legend = :topleft) + plot!(plots[1], title = "One Path of All Variables", legend = :topleft, + titlefontsize = 12) # plot martingale component plot!(plots[2], trange, mpath[1, :], color = :magenta, label = "") @@ -605,7 +607,8 @@ function plot_given_paths(T, ypath, mpath, spath, tpath, mbounds, sbounds; label = "") plot!(plots[2], seriestype = :hline, [horline], color = :black, linestyle = :dash, label = "") - plot!(plots[2], title = "Martingale Components for Many Paths") + plot!(plots[2], title = "Martingale Components for Many Paths", + titlefontsize = 12) # plot stationary component plot!(plots[3], spath[1, :], color = :green, label = "") @@ -616,7 +619,8 @@ function plot_given_paths(T, ypath, mpath, spath, tpath, mbounds, sbounds; label = "") plot!(plots[3], seriestype = :hline, [horline], color = :black, linestyle = :dash, label = "") - plot!(plots[3], title = "Stationary Components for Many Paths") + plot!(plots[3], title = "Stationary Components for Many Paths", + titlefontsize = 12) # plot trend component if show_trend == true @@ -624,7 +628,8 @@ function plot_given_paths(T, ypath, mpath, spath, tpath, mbounds, sbounds; end plot!(plots[4], seriestype = :hline, [horline], color = :black, linestyle = :dash, label = "") - plot!(plots[4], title = "Trend Components for Many Paths") + plot!(plots[4], title = "Trend Components for Many Paths", + titlefontsize = 12) return plots end @@ -640,7 +645,8 @@ function plot_martingale_paths(T, mpath, mbounds; # plot martingale component ub = mbounds[2, :] lb = mbounds[1, :] - #plot!(plt, lb, fillrange = ub, alpha = 0.25, color = :magenta, label = "") + + plot!(plt, ub, fillrange = lb, alpha = 0.25, color = :magenta, label = "") plot!(plt, seriestype = :hline, [horline], color = :black, linestyle = :dash, label = "") plot!(plt, trange, Matrix(mpath'), linewidth = 0.25, color = :black, @@ -657,7 +663,7 @@ For now, we just plot $y_t$ and $x_t$, postponing until later a description of e --- tags: [remove-cell] --- -Random.seed!(42); +Random.seed!(43); ``` ```{code-cell} julia @@ -685,16 +691,16 @@ x, y = simulate(amf.lss, T) plt_1 = plot() plt_2 = plot() plots = [plt_1, plt_2] -# plots = plot(layout = (2, 1)) plot!(plots[1], 1:T, y[amf.nx + 1, :], color = :black, lw = 2, label = "") -plot!(plots[1], title = L"A particular path of $y_t$") +plot!(plots[1], title = L"A particular path of $y_t$", + titlefontsize = 12) plot!(plots[2], 1:T, y[1, :], color = :green, lw = 2, label = "") plot!(plots[2], seriestype = :hline, [0], color = :black, lw = 2, linestyle = :dashdot, label = "") -plot!(plots[2], title = L"Associated path of $x_t$") -# plot(plots) -plot(plots[1], plots[2], layout = (2, 1), size = (700, 500)) +plot!(plots[2], title = L"Associated path of $x_t$", + titlefontsize = 12) +plot(plots[1], plots[2], layout = (2, 1), size = (700, 600)) ``` ```{code-cell} julia @@ -933,12 +939,6 @@ $\widetilde M_t$ of the multiplicative decomposition has a peculiar property. The following simulation of many paths of $\widetilde M_t$ illustrates this property -```{code-cell} julia ---- -tags: [remove-cell] ---- -Random.seed!(10021987); -``` ```{code-cell} julia plt = plot_martingales(amf, 12000) diff --git a/lectures/time_series_models/multiplicative_functionals.md b/lectures/time_series_models/multiplicative_functionals.md index c835a9f5..6f1857d5 100644 --- a/lectures/time_series_models/multiplicative_functionals.md +++ b/lectures/time_series_models/multiplicative_functionals.md @@ -422,7 +422,8 @@ Random.seed!(42); ```{code-cell} julia # Create the second (wrong) alternative model -amf2 = AMF_LSS_VAR(A = 0.9, B = 1.0, D = 0.55, F = 0.25) # parameters for theta_1 closer to theta_0 +# parameters for theta_1 closer to theta_0 +amf2 = AMF_LSS_VAR(A = 0.9, B = 1.0, D = 0.55, F = 0.25) # Get likelihood from each path x^{i}, y^{i} LLit2 = simulate_likelihood(amf2, Xit, Yit) @@ -604,10 +605,10 @@ amc, mmc = simulate_martingale_components(amf_2, 1_000, 5_000) amcT = amc[:, end] mmcT = mmc[:, end] -println("The (min, mean, max) of additive Martingale component in period T is") +println("The (min, mean, max) of additive Martingale component in period T:") println("\t ($(minimum(amcT)), $(mean(amcT)), $(maximum(amcT)))") -println("The (min, mean, max) of multiplicative Martingale component in period T is") +println("The (min, mean, max) of multiplicative Martingale component in period T:") println("\t ($(minimum(mmcT)), $(mean(mmcT)), $(maximum(mmcT)))") ``` @@ -708,13 +709,11 @@ dens_to_plot = [Mtilde_t_density(amf_2, t, xmin = 1e-8, xmax = 6.0) ldens_to_plot = [logMtilde_t_density(amf_2, t, xmin = -10.0, xmax = 10.0) for t in times_to_plot] -# plot_title = "Densities of M_t^tilda" is required, however, plot_title is not yet -# supported in Plots plots = plot(layout = (3, 2), size = (600, 800)) for (it, dens_t) in enumerate(dens_to_plot) x, pdf = dens_t - plot!(plots[it], title = "Density for time (time_to_plot[it])", + plot!(plots[it], title = "Density for time $(times_to_plot[it])", titlefontsize = 10) plot!(plots[it], pdf, fillrange = 0, label = "") end