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