cube-root-minus-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-minus-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 = (1/3)*pi
020| point2 = (5/3)*pi
021| point3 = (2/3)*pi
022| point4 = (4/3)*pi
023| 
024| arr_kw = dict(color='#c0c0c0', zorder=20, width=0.010, head_width=0.03, length_includes_head=True)
025| 
026| ##================================================================================================##
027| def main ():
028|     fig, ax = plt.subplots()
029|     fig.suptitle('Cube Roots of Minus One', fontsize=24, fontweight='bold')
030|     fig.set_figwidth(8.8)
031|     fig.set_figheight(9.2)
032|     fig.subplots_adjust(left=0.10, right=0.98, bottom=0.07, top=0.94)
033| 
034|     ax.set_xlabel('Real Value', fontsize=20)
035|     ax.set_xlim(xmin, xmax)
036|     ax.xaxis.set_major_locator(MultipleLocator(1.00))
037|     ax.xaxis.set_minor_locator(MultipleLocator(0.10))
038|     ax.xaxis.set_major_formatter(FormatStrFormatter('%+.1f'))
039| 
040|     ax.set_ylabel('Imaginary Value', fontsize=20)
041|     ax.set_ylim(ymin, ymax)
042|     ax.yaxis.set_major_locator(MultipleLocator(1.00))
043|     ax.yaxis.set_minor_locator(MultipleLocator(0.10))
044|     ax.yaxis.set_major_formatter(FormatStrFormatter('%+.1f'))
045| 
046|     ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
047|     ax.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
048|     ax.tick_params(which='major', axis='both', direction='out', color='#000000')
049|     ax.tick_params(which='minor', axis='both', direction='out', color='#000000')
050| 
051|     ns = 90
052|     ss = [2*pi*(s/ns) for s in range(ns+1)]
053|     xs = [cos(a) for a in ss]
054|     ys = [sin(a) for a in ss]
055|     ax.plot(xs,ys, c='blue', lw=3.0, alpha=0.80, zorder=10)
056| 
057|     xs = [0.0, point0[0], cos(point1), cos(point2), cos(point3), cos(point4)]
058|     ys = [0.0, point0[1], sin(point1), sin(point2), sin(point3), sin(point4)]
059|     cs = ['black', 'red', 'red', 'red', '#800080', '#800080']
060|     ax.scatter(xs,ys, color=cs, s=90, alpha=0.75, zorder=21)
061|     #ax.arrow(xs[0],ys[0], xs[1],ys[1], **arr_kw)
062|     #ax.arrow(xs[0],ys[0], xs[2],ys[2], **arr_kw)
063|     #ax.arrow(xs[0],ys[0], xs[3],ys[3], **arr_kw)
064| 
065|     xs = [point0[0], cos(point1), cos(point2), point0[0]]
066|     ys = [point0[1], sin(point1), sin(point2), point0[1]]
067|     ax.add_line(lines.Line2D(xs,ys, color='#007f00', lw=2.0,ls='--', zorder=19))
068| 
069|     fig.savefig(FileName)
070|     print(f'wrote: {FileName}')
071|     print()
072| 
073| ####################################################################################################
074| if __name__ == '__main__':
075|     print(argv[0])
076|     print()
077|     main()
078|     print()
079| ####################################################################################################
080| '''eof'''
081|