square-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, 'square-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 = ( 0.0, +1.0)
020| point2 = ( 0.0, -1.0)
021| 
022| arr_kw = dict(zorder=20, width=0.010, head_width=0.03, length_includes_head=True)
023| 
024| ##================================================================================================##
025| def make_chart (data):
026|     fig, ax = plt.subplots()
027|     fig.suptitle('Square Roots of Minus 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], point1[0], point2[0]]
053|     ys = [0.0, point0[1], point1[1], point2[1]]
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], color='#ff0000', **arr_kw)
057|     ax.arrow(xs[0],ys[0], xs[2],ys[2], color='#008000', **arr_kw)
058|     ax.arrow(xs[0],ys[0], xs[3],ys[3], color='#800080', **arr_kw)
059| 
060|     fig.set_figwidth(8.8)
061|     fig.set_figheight(9.2)
062|     fig.subplots_adjust(left=0.10, right=0.98, bottom=0.07, top=0.94)
063|     fig.savefig(FileName)
064|     print(f'wrote: {FileName}')
065|     print()
066| 
067| ##================================================================================================##
068| def main ():
069|     make_chart()
070| 
071| ####################################################################################################
072| if __name__ == '__main__':
073|     print(argv[0])
074|     print()
075|     main()
076|     print()
077| ####################################################################################################
078| '''eof'''
079|