In [1]:
%matplotlib inline
#%matplotlib notebook
%load_ext version_information
%load_ext autoreload
In [2]:
import datetime
import os
import sys
import warnings
warnings.simplefilter("ignore")
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import spacepy.datamodel as dm
import spacepy.plot as spp
import spacepy.toolbox as tb
import tqdm
import pymc3 as mc3
from matplotlib.animation import FuncAnimation
from IPython.display import HTML
from matplotlib import animation, rc
%version_information matplotlib, numpy, pandas
Out[2]:
In [3]:
plt.rcParams['figure.figsize'] = [10, 6]
plt.rcParams['savefig.dpi'] = plt.rcParams['figure.dpi'] # 72
%config InlineBackend.figure_format = 'retina'
In [12]:
with mc3.Model():
mean = mc3.Uniform('mean', -10, 10)
std = mc3.Uniform('std', 0, 20)
A = mc3.Normal('A', mean, std, observed=np.random.normal(loc=0, scale=10, size=20))
trace = mc3.sample(1000, discard_tuned_samples=False)
In [13]:
mc3.traceplot(trace, combined=True)
Out[13]:
In [14]:
len(trace)
Out[14]:
In [22]:
# First set up the figure, the axis, and the plot element we want to animate
fig, ax = plt.subplots()
ax.set_xlim(( -7.5, 7.5))
ax.set_ylim((5, 17.5))
line, = ax.plot([], [], lw=1,)
ax.set_xlabel('Mean')
ax.set_ylabel('std')
# initialization function: plot the background of each frame
def init():
line.set_data([], [])
return (line,)
# animation function. This is called sequentially
def animate(i):
x = trace['mean'][:i]
y = trace['std'][:i]
line.set_data(x, y)
return (line,)
# call the animator. blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=300, interval=50, blit=True)
HTML(anim.to_html5_video())
Out[22]:
In [ ]: