【julia】プロットのアニメーション
2020年4月23日
プロットのアニメーションを描いてみます。
using Plots, Random, LsqFit
@. model(x, p) = p[1] * cos(x) + p[2] * x * sin(x)
x = range(0, step = 0.5, length = 500)
p = [3.0, 0.2]
y = model(x, p)
y_obs = model(x, p) + 0.01 * randn(length(x))
p_est = [0.5, -0.2]
anim = @animate for i =1:500
fit = curve_fit(model, x[1:i], y_obs[1:i], p_est)
plot(x, y, xlims = (1, 50), ylims = (-20, 20), legend = false)
plot!(x, model(x, fit.param))
scatter!(x[1:i], y_obs[1:i], m = :x)
vline!([x[i]], style = :dash)
end
gif(anim, fps = 15)

うーん、面白い。
Google Colaboratory のnotebookで実行するとこんな感じ。