In [1]:
%matplotlib 
 
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as manimation

plt.ion()


Using matplotlib backend: TkAgg
/usr/lib/python2.7/dist-packages/matplotlib/__init__.py:874: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
  warnings.warn(self.msg_depr % (key, alt_key))

In [2]:
frames = 100
diff_max = np.pi
diff_min = np.pi/10

npoints=50

In [3]:
# We want a square figure with a black background

fig = plt.figure(facecolor='k', figsize=(5,5))

# Obviously a polar plot and enough space to see all the curves
ax = fig.add_subplot(111, polar=True)
ax.set_xlim(0,1.1)
ax.set_ylim(0,1.1)

# Let's put everything in black and remove the axis 
ax.set_axis_bgcolor('black')
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
for spine in ax.spines.itervalues():
    spine.set_visible(False)

In [4]:
x = np.linspace(0,2*np.pi,npoints)

line = ax.plot(np.zeros_like(x), np.ones_like(x), color='w', linewidth=40, solid_capstyle='round',solid_joinstyle='round')[0]

fig.tight_layout()

In [5]:
def init():
    return line

def basic_motion(iframe):
    return (np.sin(iframe*np.pi/(frames-1)-np.pi/2)+1)/2*2*np.pi+iframe*2*np.pi/(frames-1)

def diff_motion(iframe):
    return -diff_min+(np.sin(iframe*2*np.pi/(frames-1)+np.pi/2)-1)/2*diff_max

def update_image(iframe):
    x = np.linspace(basic_motion(iframe), basic_motion(iframe)+diff_motion(iframe), npoints)
    line.set_xdata(x)
    return line

In [6]:
map_animation = manimation.FuncAnimation(fig, update_image, init_func=init, frames=frames, interval=50, repeat=True)
plt.show()

In [7]:
map_animation.save('wait-wait.gif', writer='imagemagic', dpi=40, fps=25, savefig_kwargs=dict(facecolor=fig.get_facecolor(), edgecolor='none'))


/usr/lib/python2.7/dist-packages/matplotlib/animation.py:746: UserWarning: MovieWriter imagemagic unavailable
  warnings.warn("MovieWriter %s unavailable" % writer)

And if everything worked properly you should get a tidy gif :