Skip to main content

Posts

Showing posts with the label animation

Animations with matplotlib

For some reason this wasn't overly clear in the documentation, but a simple way to make an animation using the default backend in matplotlib is something like this: from numpy import random , array , arange import matplotlib.pyplot as plt plt . ion () print "starting" x = arange ( 100 ) y = 2 * random . rand ( 100 ) line , = plt . plot ( x , y , 'd-' ) for i in arange ( 1 , 200 ): y = y + random . rand ( 100 ) - 0.500000 line . set_data ( x , y ) ax = line . get_axes () ax . relim () ax . autoscale_view () plt . draw () # redraw the canvas plt . show ()