nor-gates.html
001| '''NOR Gates Ripple States Chart.'''
002|
003| from sys import argv
004| from os import path
005| from math import sqrt
006| import matplotlib.pyplot as plt
007| from matplotlib.ticker import NullLocator, MultipleLocator, NullFormatter, FormatStrFormatter
008|
009| BasePath = r'C:\CJS\prj\Python\blog\proj'
010| ImgsPath = path.join(BasePath, 'img')
011| Filename = 'nor-gates.png'
012|
013|
014| data = [
015| [0,0,0,0,0,0,0,0,0,0,0],
016| [1,1,1,1,1,1,1,1,1,0,0],
017| [1,0,0,0,0,0,0,0,0,1,1],
018| [1,0,0,1,1,1,1,1,0,0,0],
019| [1,0,0,1,0,0,0,0,0,1,0],
020| [1,0,0,1,0,0,1,1,0,0,0],
021| [1,0,0,1,0,0,1,0,0,1,0],
022| [1,0,0,1,0,0,1,0,0,0,0],
023| [1,0,0,1,0,0,1,0,0,0,0],
024| ]
025|
026|
027| def make_chart (data):
028| fig, ax = plt.subplots()
029| fig.suptitle('NOR Full-Adder States', fontsize=14, fontweight='bold')
030|
031| ax.set_xlabel('Ticks', fontsize=12, fontweight='bold')
032| ax.set_xlim(0.0, +8.0)
033| ax.xaxis.set_major_locator(MultipleLocator(1.0))
034| ax.xaxis.set_minor_locator(MultipleLocator(0.5))
035| ax.xaxis.set_major_formatter(FormatStrFormatter('%d'))
036|
037| ax.set_ylabel('State', fontsize=12, fontweight='bold')
038| ax.set_ylim(0.0, +2.0)
039| ax.yaxis.set_major_locator(MultipleLocator(1.0))
040| ax.yaxis.set_minor_locator(MultipleLocator(0.5))
041| ax.yaxis.set_major_formatter(FormatStrFormatter('%d'))
042|
043| ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
044| ax.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
045| ax.tick_params(which='major', axis='both', direction='out', color='#000000')
046| ax.tick_params(which='minor', axis='both', direction='out', color='#000000')
047|
048| xs, g1s, g2s, g3s, g4s, g5s, g6s, g7s, g8s, g9s, o2s, o1s = data
049|
050| ax.plot(xs,g1s, lw=2.0, alpha=0.9, zorder=11)
051| ax.plot(xs,g2s, lw=2.0, alpha=0.9, zorder=12)
052| ax.plot(xs,g3s, lw=2.0, alpha=0.9, zorder=13)
053| ax.plot(xs,g4s, lw=2.0, alpha=0.9, zorder=14)
054| ax.plot(xs,g5s, lw=2.0, alpha=0.9, zorder=15)
055| ax.plot(xs,g6s, lw=2.0, alpha=0.9, zorder=16)
056| ax.plot(xs,g7s, lw=2.0, alpha=0.9, zorder=17)
057| ax.plot(xs,g8s, lw=2.0, alpha=0.9, zorder=18)
058| ax.plot(xs,g9s, lw=2.0, alpha=0.9, zorder=19)
059| ax.plot(xs,o2s, color='#009f30', lw=3.0, alpha=0.9, zorder=21)
060| ax.plot(xs,o1s, color='#0000ff', lw=3.5, alpha=0.9, zorder=22)
061|
062| fig.set_figwidth(4.0)
063| fig.set_figheight(4.0)
064| fig.subplots_adjust(left=0.12, right=0.98, bottom=0.13, top=0.93)
065|
066| fn = path.join(ImgsPath, Filename)
067| fig.savefig(fn)
068| print(f'wrote: {fn}')
069| print()
070|
071|
072| def main ():
073| xs = range(9)
074| g1s = [x[ 0]+0.0 for x in data]
075| g2s = [x[ 1]+0.1 for x in data]
076| g3s = [x[ 2]+0.2 for x in data]
077| g4s = [x[ 3]+0.3 for x in data]
078| g5s = [x[ 4]+0.4 for x in data]
079| g6s = [x[ 5]+0.5 for x in data]
080| g7s = [x[ 6]+0.6 for x in data]
081| g8s = [x[ 7]+0.7 for x in data]
082| g9s = [x[ 8]+0.8 for x in data]
083| o2s = [x[ 9]+0.9 for x in data]
084| o1s = [x[10]+1.0 for x in data]
085|
086| data = (xs, g1s, g2s, g3s, g4s, g5s, g6s, g7s, g8s, g9s, o2s, o1s)
087|
088| make_chart(data)
089|
090|
091| if __name__ == '__main__':
092| print(argv[0])
093| print()
094| main()
095| print()
096|
097| '''eof'''
098|