from ipywidgets import interact, interactive, fixed
import ipywidgets as widgets
def plotNthRoots(n):
# Create a unit circle
c = circle((0,0), radius=1, rgbcolor=(1,0,0))
# Combine the circle with points on the circle representing the roots of unity
theta = 2.0*pi/float(n)
p = c + point([(cos(t), sin(t)) for t in srange(0, 2.0*pi, theta)],frame=True,size=60)
# Add in vectors from the origin to the roots of unity.
p = p + sum([arrow2d( (0,0), (cos(t),sin(t)) ) for t in srange(0, 2.0*pi, theta)])
show(p)
print("The Principle %d-Root: (%5.3f)+(%5.3f)I"%(n,cos(theta), sin(theta)) )
@interact
def _(n=(1,20)):
plotNthRoots(n)
Rather than creating a slider, it generates a plot for the case n=20.