Redid Discrete Bayes animations.

I added titles so you can see where in the processing the
graph is.

This surfaced a bug in matplotlib 1.5 (#5399) so I added
some code to work around that.
This commit is contained in:
Roger Labbe 2016-01-09 08:49:29 -08:00
parent 65a77d0af2
commit 6b9b97927d
4 changed files with 37 additions and 30 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 459 KiB

After

Width:  |  Height:  |  Size: 378 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 184 KiB

After

Width:  |  Height:  |  Size: 201 KiB

File diff suppressed because one or more lines are too long

View File

@ -19,6 +19,8 @@ from __future__ import (absolute_import, division, print_function,
from matplotlib import animation
import matplotlib.pyplot as plt
def animate(filename, func, frames, interval, fig=None, figsize=(6.5, 6.5)):
""" Creates an animated GIF of a matplotlib.
@ -43,19 +45,16 @@ def animate(filename, func, frames, interval, fig=None, figsize=(6.5, 6.5)):
size of the figure in inches. Defaults to 6.5" by 6.5"
"""
def forward(frame):
# I don't know if it is a bug or what, but FuncAnimation calls twice
# with the first frame number. That breaks any animation that uses
# the frame number in computations
if forward.first:
forward.first = False
return
func(frame)
def init_func():
""" This draws the 'blank' frame of the video. To work around a bug
in matplotlib 1.5.1 (#5399) you must supply an empty init function
for the save to work."""
pass
if fig is None:
fig = plt.figure(figsize=figsize)
forward.first = True
anim = animation.FuncAnimation(fig, forward, frames=frames, interval=interval)
anim = animation.FuncAnimation(fig, func, init_func=init_func,
frames=frames, interval=interval)
anim.save(filename, writer='imagemagick')