import numpy as np
import matplotlib.pyplot as plt1
from matplotlib.ticker import (MultipleLocator, FormatStrFormatter, AutoMinorLocator)
%matplotlib inline
fig, ax1a = plt1.subplots(1, figsize=(16, 8))
ax1a.clear()
#Itterations step and circumference
rationals=1000
for p in range(rationals):
n=p/(rationals/100)
#counter
k=np.arange(n)
#Determine angle and linesegment lenght
angle=k*2*np.pi/(n+1) +np.pi/(n+1)
length=1/(1+n)
#Calculate each individual vector
x=length*np.cos(angle)
y=length*np.sin(angle)
#Cumulative sum vector
xc=np.cumsum(x)
yc=np.cumsum(y)
#Add coordinate 0,0 to start and end.
xc=np.append(xc,0)
yc=np.append(yc,0)
xc=np.concatenate(([0],xc),axis=0)
yc=np.concatenate(([0],yc),axis=0)
#Plot points or circumference.
#ax1a.plot(xc,yc, marker='o', color='black', linestyle='', markersize=0.04)
#Plot all Polygon outline
ax1a.plot(xc,yc, marker='.', color='black', linestyle='-', linewidth=0.02, markersize=0,zorder=rationals+int(n))
#Plot Polygon outline inter number of sides
#if n.is_integer()==True and n<20:
# ax1a.plot(xc,yc, marker='.', color='red', linestyle='-', linewidth=0.2, markersize=0,zorder=rationals+int(n))
# ax1a.plot(xc,yc, marker='o', color='red', linestyle='', markersize=0.8,zorder=rationals+int(n))
#Plot Circle outline last polygon
ax1a.plot(xc,yc, marker='.', color='red', linestyle='-', linewidth=1.5, markersize=0,zorder=rationals++int(n)+1, label='Circle')
#ax1a.plot(xc,yc, marker='o', color='red', linestyle='', markersize=0.1,zorder=-1000,label='Discrete n (polygon)')
ax1a.plot(xc,yc, marker='o', color='black', linestyle='', markersize=0.1,zorder=-1000, label='Continuous n')
ax1a.set_xlabel('$x$',fontsize=20)
ax1a.set_ylabel('$y$',fontsize=20)
ax1a.set_title('Circle Creation, Circumference=1',fontsize=15)
ax1a.legend(loc='upper left',fontsize=12,markerscale=20,frameon=False)
ax1a.grid(b=True, which='major', color='#666666', linestyle='-', zorder=0)
ax1a.axes.set_xlim([-1,0.2])
ax1a.axes.set_ylim([0,0.6])
ax1a.xaxis.set_major_locator(MultipleLocator(0.1))
ax1a.yaxis.set_major_locator(MultipleLocator(0.1))
plt1.gca().set_aspect('equal', adjustable='box')
plt1.savefig('Circle Plot', dpi=300, bbox_inches='tight')