%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import StaticInteract, RangeWidget, RadioWidget
def plot(n):
fig, ax = plt.subplots(figsize=(4, 3),
subplot_kw={'axisbg':'#EEEEEE',
'axisbelow':True})
ax.grid(color='w', linewidth=2, linestyle='solid')
x = np.linspace(0, 2*np.pi, 100)
y = np.zeros(len(x))
i = 0
while i < n+1 :
y += (1.0/(2*i+1))*np.sin((2*i+1)*x)
i += 1
ax.plot(x, y, lw=5, alpha=0.4)
ax.set_xlim(0,2*np.pi)
ax.set_ylim(-1, 1)
return fig
StaticInteract(plot,n=RangeWidget(0, 15, 1))