blog-post-hits.html
001| '''Blog Post Reader Hits.
001|
001| title: "Madam Secretary & Scorpion"
001| id: #5979
001| url: http://logosconcarne.com/2014/10/02/madam-secretary-scorpion/
001|
001| '''
002|
003| from sys import argv
004| from os import path
005| from datetime import date
006| from math import sqrt
007| import matplotlib.pyplot as plt
008| from matplotlib.ticker import NullLocator, MultipleLocator, NullFormatter, FormatStrFormatter
009| from matplotlib.dates import YearLocator, MonthLocator, DateFormatter
010|
011| BasePath = r'C:\CJS\prj\Python\blog\proj'
012| ImgsPath = path.join(BasePath, 'img')
013| Filename = 'blog-post-006145.png'
014|
015|
016| HitData = [
017| [2014, 0, 0, 0, 0, 0, 0, 0, 0, 0,102, 18, 25, 145],
018| [2015, 15, 3, 12, 5, 11, 2, 3, 2, 8, 9, 3, 8, 81],
019| [2016, 1, 2, 3, 3, 0, 1, 2, 0, 3, 2, 3, 1, 21],
020| [2017, 1, 0, 6, 0, 3, 0, 0, 2, 6, 2, 0, 0, 20],
021| [2018, 0, 1, 0, 0, 0, 0, 1, 0, 26, 0, 3, 4, 35],
022| [2019, 4, 0, 4, 3, 4, 3, 0, 0, 31, 0, 0, 2, 51],
023| [2020, 7, 5, 12, 18, 2, 4, 1, 6, 32, 3, 0, 0, 90],
024| ]
025|
026|
027| def make_chart (xs, ys):
028| fig, ax = plt.subplots()
029| fig.suptitle('Leon Wieselteir post from Oct 13, 2014')
030|
031| ax.set_xlabel('Page Hits per Month', fontsize=10)
032| ax.xaxis_date()
033| ax.set_xlim(date(2014,1,1), date(2020,12,31))
034| ax.xaxis.set_major_locator(YearLocator(1))
035| ax.xaxis.set_minor_locator(MonthLocator(bymonth=(4,7,10)))
036| ax.xaxis.set_major_formatter(DateFormatter('%Y'))
037|
038|
039|
040|
041|
042| ax.set_ylabel('Hits', fontsize=10)
043| ax.set_ylim(0, +40)
044| ax.yaxis.set_major_locator(MultipleLocator(10))
045| ax.yaxis.set_minor_locator(MultipleLocator(2.5))
046| ax.yaxis.set_major_formatter(FormatStrFormatter('%d'))
047|
048| ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.0,ls='-',zorder=1, alpha=1.0)
049| ax.grid(which='minor', axis='both', color='#bfbfbf', lw=0.5,ls='-',zorder=0, alpha=1.0)
050| ax.tick_params(which='major', axis='both', direction='out', color='#000000')
051| ax.tick_params(which='minor', axis='both', direction='out', color='#000000')
052|
053| ax.bar(xs,ys, color='#7f0000', width=25, alpha=0.80, zorder=10)
054|
055| fig.set_figwidth(8.0)
056| fig.set_figheight(3.0)
057| fig.subplots_adjust(left=0.07, right=0.99, bottom=0.17, top=0.90)
058|
059| fn = path.join(ImgsPath, Filename)
060| fig.savefig(fn)
061|
062|
063| def main ():
064| xs = []
065| ys = []
066| for rcds in HitData:
067| year = rcds[0]
068| for mx,m in enumerate(rcds[1:13]):
069| xs.append(date(year, mx+1, 1))
070| ys.append(m)
071|
072| make_chart(xs, ys)
073|
074|
075| if __name__ == '__main__':
076| print(argv[0])
077| print()
078| main()
079| print()
080|
081| '''eof'''
082|