import numpy as np
import pylab as plt
import itertools
n = 13
roots = np.roots( [1,] + [0,]*(n-1) + [-1,] )
colors = itertools.cycle(['r', 'g', 'b', 'y'])
plt.figure(figsize=(6,6))
for root in roots:
plt.arrow(0,0,root.real,root.imag,ec=colors.next())
plt.xlim(-1.5,1.5)
plt.ylim(-1.5,1.5)
plt.show()
The roots of unity are calculated in a manner similar to this answer.
Update: If you want to use seaborn
, you can get unique colors quite easily:
import numpy as np
import pylab as plt
import itertools
import seaborn as sns
n = 13
colors = sns.color_palette("hls", n)
roots = np.roots( [1,] + [0,]*(n-1) + [-1,] )
# Sorted by angle
idx = np.argsort([np.angle(x) for x in roots])
roots = roots[idx]
plt.figure(figsize=(6,6))
for root,c in zip(roots,colors):
plt.arrow(0,0,root.real,root.imag,ec=c,lw=3)
plt.xlim(-1.25,1.25)
plt.ylim(-1.25,1.25)
plt.show()