z_full-adder-code.html
001|
002| from os import path
003| from datetime import date
004| import matplotlib.pyplot as plt
005| from matplotlib.ticker import NullLocator, MultipleLocator, NullFormatter, FormatStrFormatter
006| from matplotlib.dates import DayLocator, MonthLocator, YearLocator, DateFormatter
007|
008| BasePath = r'C:\CJS\prj\Python\blog\hcc'
009| ImgsPath = path.join(BasePath,'img')
010|
011|
012| FullAdderCode = [
013| [2019, 0, 0, 0, 0, 11, 1, 0, 1, 1, 0, 2, 0, 16],
014| [2020, 0, 0, 1, 1, 0, 0, 0, 0, 0, 6, 17, 13, 38],
015| [2021, 10, 8, 0, 8, 4, 6, 11, 8, 12, 8, 6, 15, 96],
016| [2022, 22, 14, 23, 23, 11, 5, 0, 1, 2, 0, 0, 0, 101],
017| [2023, 1, 3, 12, 9, 3, 3, 8, 4, 4, 14, 5, 6, 72],
018| [2024, 9, 12, 16, 15, 29, 18, 16,295,165,100, 59, 66, 800],
019| ]
020|
021| FullAdderCodeDays = [
022| (date(2024, 8, 2), 1),
023| (date(2024, 8, 8), 1),
024| (date(2024, 8,10), 1),
025| (date(2024, 8,13), 1),
026| (date(2024, 8,19), 1),
027| (date(2024, 8,27),127), (date(2024, 8,28), 82), (date(2024, 8,29), 33),
028| (date(2024, 8,30), 21), (date(2024, 8,31), 26), (date(2024, 9, 1), 22),
029| (date(2024, 9, 2), 5), (date(2024, 9, 3), 13), (date(2024, 9, 4), 5),
030| (date(2024, 9, 5), 5), (date(2024, 9, 6), 3), (date(2024, 9, 7), 6),
031| (date(2024, 9, 8), 11), (date(2024, 9, 9), 6), (date(2024, 9,10), 10),
032| (date(2024, 9,11), 11), (date(2024, 9,12), 6), (date(2024, 9,13), 0),
033| (date(2024, 9,14), 1), (date(2024, 9,15), 3), (date(2024, 9,16), 3),
034| (date(2024, 9,17), 1), (date(2024, 9,18), 9), (date(2024, 9,19), 2),
035| (date(2024, 9,20), 0), (date(2024, 9,21), 2), (date(2024, 9,22), 3),
036| (date(2024, 9,23), 7), (date(2024, 9,24), 7), (date(2024, 9,25), 0),
037| (date(2024, 9,26), 1), (date(2024, 9,27), 12), (date(2024, 9,28), 3),
038| (date(2024, 9,29), 2), (date(2024, 9,30), 4), (date(2024,10, 1), 3),
039| (date(2024,10, 2), 1), (date(2024,10, 3), 3), (date(2024,10, 4), 2),
040| (date(2024,10, 5), 1), (date(2024,10, 6), 3), (date(2024,10, 7), 2),
041| (date(2024,10, 8), 1), (date(2024,10, 9), 2), (date(2024,10,10), 6),
042| (date(2024,10,11), 3), (date(2024,10,12), 4), (date(2024,10,13), 2),
043| (date(2024,10,14), 10), (date(2024,10,15), 8), (date(2024,10,16), 3),
044| (date(2024,10,17), 1), (date(2024,10,18), 2), (date(2024,10,19), 5),
045| (date(2024,10,20), 4), (date(2024,10,21), 2), (date(2024,10,22), 4),
046| (date(2024,10,23), 4), (date(2024,10,24), 3), (date(2024,10,25), 4),
047| (date(2024,10,26), 3), (date(2024,10,27), 1), (date(2024,10,28), 0),
048| (date(2024,10,29), 2), (date(2024,10,30), 1), (date(2024,10,31), 10),
049| (date(2024,11, 1), 1), (date(2024,11, 2), 1), (date(2024,11, 3), 3),
050| (date(2024,11, 4), 1), (date(2024,11, 5), 2), (date(2024,11, 6), 0),
051| (date(2024,11, 7), 1), (date(2024,11, 8), 0), (date(2024,11, 9), 3),
052| (date(2024,11,10), 1), (date(2024,11,11), 3), (date(2024,11,12), 1),
053| (date(2024,11,13), 6), (date(2024,11,14), 2), (date(2024,11,15), 3),
054| (date(2024,11,16), 2), (date(2024,11,17), 1), (date(2024,11,18), 3),
055| (date(2024,11,19), 2), (date(2024,11,20), 1), (date(2024,11,21), 8),
056| (date(2024,11,22), 2), (date(2024,11,23), 3), (date(2024,11,24), 1),
057| (date(2024,11,25), 1), (date(2024,11,26), 1), (date(2024,11,27), 3),
058| (date(2024,11,28), 0), (date(2024,11,29), 3), (date(2024,11,30), 0),
059| (date(2024,12, 1), 4), (date(2024,12, 2), 4), (date(2024,12, 3), 0),
060| (date(2024,12, 4), 0), (date(2024,12, 5), 6), (date(2024,12, 6), 0),
061| (date(2024,12, 7), 4), (date(2024,12, 8), 3), (date(2024,12, 9), 4),
062| (date(2024,12,10), 2), (date(2024,12,11), 1), (date(2024,12,12), 0),
063| (date(2024,12,13), 5), (date(2024,12,14), 2), (date(2024,12,15), 0),
064| (date(2024,12,16), 0), (date(2024,12,17), 3), (date(2024,12,18), 3),
065| (date(2024,12,19), 3), (date(2024,12,20), 3), (date(2024,12,21), 2),
066| (date(2024,12,22), 4), (date(2024,12,23), 0), (date(2024,12,24), 5),
067| (date(2024,12,25), 1), (date(2024,12,26), 0), (date(2024,12,27), 4),
068| (date(2024,12,28), 0), (date(2024,12,29), 2), (date(2024,12,30), 1),
069| (date(2024,12,31), 0),
070| ]
071|
072|
073|
074| def full_adder_code_views (data, fname='full-adder-code.png', fpath=ImgsPath):
075| filename = path.join(fpath,fname) if fpath else fname
076|
077|
078| fig, ax = plt.subplots()
079| fig.set_figwidth(8.0)
080| fig.set_figheight(4.0)
081| fig.subplots_adjust(left=0.080, right=0.990, bottom=0.18, top=0.92)
082|
083| fig.suptitle('The Hard-Core Coder, "Full Adder Code" post', fontsize=14, fontweight='bold')
084|
085| ax.xaxis_date()
086| ax.set_xlabel('Month', fontsize=12, fontweight='bold')
087| ax.set_xlim(date(2019,1,1), date(2025,2,1))
088| ax.xaxis.set_major_locator(YearLocator(month=1))
089| ax.xaxis.set_minor_locator(MonthLocator(bymonth=[4,7,10]))
090| ax.xaxis.set_major_formatter(DateFormatter('%b %y'))
091|
092| for tick in ax.xaxis.get_major_ticks():
093| tick.label1.set_rotation('vertical')
094| tick.label1.set_size(9)
095|
096| ax.set_ylabel('Views', fontsize=12, fontweight='bold')
097| ax.set_ylim(0, 300)
098| ax.yaxis.set_major_locator(MultipleLocator(50))
099| ax.yaxis.set_minor_locator(MultipleLocator(10))
100| ax.yaxis.set_major_formatter(FormatStrFormatter('%d'))
101|
102| ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
103| ax.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
104| ax.tick_params(which='major', axis='both', direction='out', color='#000000')
105| ax.tick_params(which='minor', axis='both', direction='out', color='#000000')
106|
107| xs = [d[0] for d in data]
108| ys = [d[1] for d in data]
109| ax.bar(xs,ys, width=25, color='#ff0000', alpha=0.95, zorder=11)
110|
111| fig.savefig(filename)
112| print(f'wrote: {filename}')
113| print()
114|
115|
116| def full_adder_code_days (data, fname='full-adder-code-days.png', fpath=ImgsPath):
117| filename = path.join(fpath,fname) if fpath else fname
118|
119|
120| fig, ax = plt.subplots()
121| fig.set_figwidth(8.0)
122| fig.set_figheight(4.0)
123| fig.subplots_adjust(left=0.083, right=0.995, bottom=0.195, top=0.92)
124|
125| fig.suptitle('The Hard-Core Coder, "Full Adder Code" post', fontsize=14, fontweight='bold')
126|
127| ax.xaxis_date()
128| ax.set_xlabel('Date', fontsize=12, fontweight='bold')
129| ax.set_xlim(date(2024,8,1), date(2025,1,31))
130| ax.xaxis.set_major_locator(DayLocator(bymonthday=[1,15]))
131| ax.xaxis.set_minor_locator(DayLocator(interval=1))
132| ax.xaxis.set_major_formatter(DateFormatter('%m/%d/%y'))
133|
134| for tick in ax.xaxis.get_major_ticks():
135| tick.label1.set_rotation('vertical')
136| tick.label1.set_size(9)
137|
138| ax.set_ylabel('Views per Day', fontsize=12, fontweight='bold')
139| ax.set_ylim(0, 150)
140| ax.yaxis.set_major_locator(MultipleLocator(50))
141| ax.yaxis.set_minor_locator(MultipleLocator(10))
142| ax.yaxis.set_major_formatter(FormatStrFormatter('%d'))
143|
144| ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
145| ax.grid(which='minor', axis='x', color='#dfdfdf', lw=0.6,ls='-',zorder=0, alpha=1.0)
146| ax.grid(which='minor', axis='y', color='#9f9f9f', lw=0.9,ls='-',zorder=0, alpha=1.0)
147| ax.tick_params(which='major', axis='both', direction='out', color='#000000')
148| ax.tick_params(which='minor', axis='both', direction='out', color='#000000')
149|
150| xs = [d[0] for d in data]
151| ys = [d[1] for d in data]
152| ax.bar(xs,ys, width=1.05, color='#ff0000', align='edge', alpha=0.95, zorder=11)
153|
154| fig.savefig(filename)
155| print(f'wrote: {filename}')
156| print()
157|
158|
159|
160| if __name__ == '__main__':
161| print()
162| data = [
163| (date(row[0],ix+1,1), views)
164| for row in FullAdderCode
165| for ix,views in enumerate(row[1:13]) if views
166| ]
167| full_adder_code_views(data)
168| full_adder_code_days(FullAdderCodeDays)
169| print()
170|
171| '''eof'''
172|