cube-root-one.html


001| ####################################################################################################
002| from sys import argv
003| from os import path
004| from math import pi,tau, sin,cos
005| from cmath import exp
006| import matplotlib.pyplot as plt
007| import matplotlib.lines as lines
008| from matplotlib.ticker import MultipleLocator, FormatStrFormatter
009| ####################################################################################################
010| BasePath = r'C:\CJS\prj\Python\blog\proj'
011| ImgsPath = path.join(BasePath, 'img')
012| FileName = path.join(ImgsPath, 'cube-root-one.png')
013| 
014| ##------------------------------------------------------------------------------------------------##
015| xmin,xmax = (-1.2, +1.2)
016| ymin,ymax = (-1.2, +1.2)
017| 
018| point0 = (1.0, 0.0)
019| point1 = (2/3)*pi
020| point2 = (4/3)*pi
021| 
022| arr_kw = dict(color='#c0c0c0', zorder=20, width=0.010, head_width=0.03, length_includes_head=True)
023| 
024| ##================================================================================================##
025| def main ():
026|     fig, ax = plt.subplots()
027|     fig.suptitle('Cube Roots of Unity (One)', fontsize=24, fontweight='bold')
028| 
029|     ax.set_xlabel('Real Value', fontsize=20)
030|     ax.set_xlim(xmin, xmax)
031|     ax.xaxis.set_major_locator(MultipleLocator(1.00))
032|     ax.xaxis.set_minor_locator(MultipleLocator(0.10))
033|     ax.xaxis.set_major_formatter(FormatStrFormatter('%+.1f'))
034| 
035|     ax.set_ylabel('Imaginary Value', fontsize=20)
036|     ax.set_ylim(ymin, ymax)
037|     ax.yaxis.set_major_locator(MultipleLocator(1.00))
038|     ax.yaxis.set_minor_locator(MultipleLocator(0.10))
039|     ax.yaxis.set_major_formatter(FormatStrFormatter('%+.1f'))
040| 
041|     ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
042|     ax.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
043|     ax.tick_params(which='major', axis='both', direction='out', color='#000000')
044|     ax.tick_params(which='minor', axis='both', direction='out', color='#000000')
045| 
046|     ns = 90
047|     ss = [2*pi*(s/ns) for s in range(ns+1)]
048|     xs = [cos(a) for a in ss]
049|     ys = [sin(a) for a in ss]
050|     ax.plot(xs,ys, c='blue', lw=3.0, alpha=0.80, zorder=10)
051| 
052|     xs = [0.0, point0[0], cos(point1), cos(point2)]
053|     ys = [0.0, point0[1], sin(point1), sin(point2)]
054|     cs = ['black', 'red', 'red', 'red']
055|     ax.scatter(xs,ys, color=cs, s=90, alpha=0.75, zorder=21)
056|     #ax.arrow(xs[0],ys[0], xs[1],ys[1], **arr_kw)
057|     #ax.arrow(xs[0],ys[0], xs[2],ys[2], **arr_kw)
058|     #ax.arrow(xs[0],ys[0], xs[3],ys[3], **arr_kw)
059| 
060|     xs = [point0[0], cos(point1), cos(point2), point0[0]]
061|     ys = [point0[1], sin(point1), sin(point2), point0[1]]
062|     ax.add_line(lines.Line2D(xs,ys, color='#007f00', lw=2.0,ls='--', zorder=19))
063| 
064|     fig.set_figwidth(8.8)
065|     fig.set_figheight(9.2)
066|     fig.subplots_adjust(left=0.10, right=0.98, bottom=0.07, top=0.94)
067|     fig.savefig(FileName)
068|     print(f'wrote: {FileName}')
069|     print()
070| 
071| ####################################################################################################
072| if __name__ == '__main__':
073|     print(argv[0])
074|     print()
075|     main()
076|     print()
077| ####################################################################################################
078| '''eof'''
079|