notes-likes.html


001| """Substack Notes Likes: A Histogram.
001| 
001|     count = 872
001|     total = 3343.0
001|     range = 145
001|     max   = 145
001|     min   = 0
001|     avg   = 3.833715596330275
001|     stdev = 6.336953725933237
001| 
001|     max-bin = 163
001| 
001| wrote: C:\CJS\prj\Python\blog\substack\notes-likes.png
001| 
001| 
001| Hit any key to close this window...
001| """

002| ####################################################################################################
003| from sys import argv
004| from os import path
005| from goodies import stddev
006| from mlchart import mlchart
007| ####################################################################################################
008| BasePath = r'C:\CJS\prj\Python\blog\substack'
009| 
010| ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
011| class mlchart_note_likes (mlchart):
012|     def __init__ (self, data, **kwargs):
013|         super().__init__((12.0, 4.0), **kwargs)
014|         self.data = data
015|         self.title = 'Substack Note Likes Histogram'
016|         self.x_title = 'Number of Likes'
017|         self.y_title = 'Number of Notes'
018|         self.x_limit = (-2, 150)
019|         self.y_limit = (0, 200)
020|         self.x_grids = (10, 5)
021|         self.y_grids = (50, 10)
022|         self.x_tickf = '%d'
023|         self.y_tickf = '%d'
024|         self.x_tickr = True         # rotate X axis
025|         self.x_dates = False        # use make_x_date_axis
026|         self.title_kw['fontsize'] = 14
027|         self.title_kw['fontweight'] = 'bold'
028|         self.x_title_kw['fontsize'] = 12
029|         self.y_title_kw['fontsize'] = 12
030|         self.fpath = BasePath
031|         self.fname = 'notes-likes.png'
032|         self.margins = dict(left=0.055, right=0.995, bottom=0.15, top=0.92)
033| 
034|     def plotter (self):
035|         #self.ax.set_yscale('log')
036|         xs = self.data[0]
037|         ys = self.data[1]
038|         self.ax.bar(xs,ys, width=0.8, color='#ff3300', alpha=0.95, zorder=11)
039| 
040| ##------------------------------------------------------------------------------------------------##
041| ## last Note: https://substack.com/@wyrdsmythe/note/c-104559617 [3/30]
042| Data = '''
042| 3 9 1 6 1 1 1 2 6 1 3 4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10 3 1 1 2 5 3 1 3 4 5 3 6 3 5 5 8 4 5 5 2 6 3 6 2 4 4 15 5 4
042| 4 12 4 2 8 4 7 4 5 4 2 1 2 12 9 6 1 4 4 1 3 2 2 3 3 11 4 4 2 3 1 1 2 1
042| 4 5 1 4 1 3 51 2 3 2 6 4 2 3 1 2 1 4 1 1 2 5 1 3 2 1 1 1 1 4 1 2 4 4 2
042| 3 4 2 2 4 3 5 5 6 2 3 2 6 11 10 3 2 3 4 2 4 4 3 1 6 1 4 4 2 6 3 2 6 2
042| 1 3 9 2 1 1 2 3 4 5 2 2 4 1 3 6 3 6 2 15 5 2 3 2 2 2 10 1 7 6 5 2 6 5
042| 6 3 2 1 3 2 6 6 5 3 1 2 1 5 10 9 3 1 1 1 13 2 4 5 15 2 6 3 3 2 1 5 1 6
042| 3 6 1 5 1 5 5 5 2 6 8 7 4 3 2 4 1 6 3 3 1 1 1 1 2 1 1 2 1 1 1 1 3 1 3
042| 5 1 1 1 1 1 2 1 2 1 2 1 1 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 2 0 0 4 2 0 4
042| 8 2 0 0 0 2 1 0 3 0 1 0 0 0 0 1 0 0 0 0 2 0 0 0 1 1 2 0 0 2 0 1 1 1 0
042| 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 3 0 0 2 1 0 0 0 0 0 0 0 0 2 0 1 1
042| 0 1 3 0 0 1 1 0 0 0 0 0 2 1 0 3 0 1 0 4 2 0 5 0 1 6 1 2 1 1
042| '''

043| 
044| Links = [
045|     'https://substack.com/@wyrdsmythe/note/c-59087573',
046|     'https://substack.com/@wyrdsmythe/note/c-59131320',
047|     'https://substack.com/@wyrdsmythe/note/c-59143253',
048|     'https://substack.com/@wyrdsmythe/note/c-59593646',
049|     'https://substack.com/@wyrdsmythe/note/c-59908025',
050|     'https://substack.com/@wyrdsmythe/note/c-60419542',
051|     'https://substack.com/@wyrdsmythe/note/c-60420179',
052|     'https://substack.com/@wyrdsmythe/note/c-61451702',
053|     'https://substack.com/@wyrdsmythe/note/c-62335503',
054|     'https://substack.com/@wyrdsmythe/note/c-62337295',
055|     'https://substack.com/@wyrdsmythe/note/c-63040715',
056|     'https://substack.com/@wyrdsmythe/note/c-63275630',
057|     'https://substack.com/@wyrdsmythe/note/c-63398566',
058|     'https://substack.com/@wyrdsmythe/note/c-64271708',
059|     'https://substack.com/@wyrdsmythe/note/c-64678007',
060|     'https://substack.com/@wyrdsmythe/note/c-64746744',
061|     'https://substack.com/@wyrdsmythe/note/c-65779396',
062|     'https://substack.com/@wyrdsmythe/note/c-65803031',
063|     'https://substack.com/@wyrdsmythe/note/c-65892317',
064|     'https://substack.com/@wyrdsmythe/note/c-67154487',
065|     'https://substack.com/@wyrdsmythe/note/c-67260022',
066|     'https://substack.com/@wyrdsmythe/note/c-67576678',
067|     'https://substack.com/@wyrdsmythe/note/c-67790794',
068|     'https://substack.com/@wyrdsmythe/note/c-68679435',
069|     'https://substack.com/@wyrdsmythe/note/c-71908499',
070|     'https://substack.com/@wyrdsmythe/note/c-75058300',
071|     'https://substack.com/@wyrdsmythe/note/c-75192837',
072|     'https://substack.com/@wyrdsmythe/note/c-75200558',
073|     'https://substack.com/@wyrdsmythe/note/c-75375100',
074|     'https://substack.com/@wyrdsmythe/note/c-75058300',
075|     'https://substack.com/@wyrdsmythe/note/c-75645741',
076|     'https://substack.com/@wyrdsmythe/note/c-75687748',
077|     'https://substack.com/@wyrdsmythe/note/c-75817673',
078|     'https://substack.com/@wyrdsmythe/note/c-76007571',
079|     'https://substack.com/@wyrdsmythe/note/c-76010378',
080|     'https://substack.com/@wyrdsmythe/note/c-76012074',
081|     'https://substack.com/@wyrdsmythe/note/c-76241490',
082|     'https://substack.com/@wyrdsmythe/note/c-77153104',
083|     'https://substack.com/@wyrdsmythe/note/c-77184428',
084|     'https://substack.com/@wyrdsmythe/note/c-77587536',
085|     'https://substack.com/@wyrdsmythe/note/c-81251605',
086|     'https://substack.com/@wyrdsmythe/note/c-82383854',
087|     'https://substack.com/@wyrdsmythe/note/c-82557919',
088|     'https://substack.com/@wyrdsmythe/note/c-82673311',
089|     'https://substack.com/@wyrdsmythe/note/c-82674476',
090| ]
091| 
092| ##================================================================================================##
093| def main ():
094|     rows = Data.splitlines()
095| 
096|     nums = [int(n) for row in rows for n in row.split()]
097| 
098|     bins = {n:0 for n in range(max(nums)+1)}
099|     for n in nums:
100|         bins[n] += 1
101| 
102|     print(f'len = {len(nums)}')
103|     print(f'sum = {sum(nums)}')
104|     print(f'min = {min(nums)}')
105|     print(f'avg = {sum(nums)/len(nums):.2f}')
106|     print(f'max = {max(nums)}')
107|     print(f'max-bin = {max(v for v in bins.values())}')
108|     print()
109|     stddev(nums)
110|     print()
111| 
112|     xs = [b for b in sorted(bins)]
113|     ys = [bins[b] for b in xs]
114|     data = (xs, ys)
115| 
116|     cht = mlchart_note_likes(data)
117|     cht.make()
118|     print('wrote: %s' % path.join(cht.fpath, cht.fname))
119|     print()
120| 
121| ####################################################################################################
122| if __name__ == '__main__':
123|     print()
124|     main()
125|     print()
126| ####################################################################################################
127|