time-passes.html
001| """Passing time as a fraction of lifespan so far."""
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 = 'time-passes.png'
012|
013|
014| def make_chart (xs, ys):
015| fig, ax = plt.subplots()
016| fig.suptitle('Time Passes Faster')
017|
018| ax.set_xlabel('Age')
019| ax.set_xlim(10.0, +100.0)
020| ax.xaxis.set_major_locator(MultipleLocator(10.0))
021| ax.xaxis.set_minor_locator(MultipleLocator(1.00))
022| ax.xaxis.set_major_formatter(FormatStrFormatter('%d'))
023|
024|
025|
026|
027|
028| ax.set_ylabel('Fraction of a Year')
029| ax.set_ylim(0.0, +10.0)
030| ax.yaxis.set_major_locator(MultipleLocator(1.0))
031| ax.yaxis.set_minor_locator(MultipleLocator(0.1))
032| ax.yaxis.set_major_formatter(FormatStrFormatter('%d%%'))
033|
034| ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
035| ax.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
036| ax.tick_params(which='major', axis='both', direction='out', color='#000000')
037| ax.tick_params(which='minor', axis='both', direction='out', color='#000000')
038|
039| ax.plot(xs,ys, color='#0000ff', lw=2.00, zorder=11, alpha=0.85)
040|
041| fig.set_figwidth(8.0)
042| fig.set_figheight(6.0)
043| fig.subplots_adjust(left=0.095, right=0.985, bottom=0.09, top=0.94)
044|
045| fn = path.join(ImgsPath, Filename)
046| fig.savefig(fn)
047| print('wrote: %s' % fn)
048| print()
049|
050|
051| def main ():
052| xs = [float(x/10) for x in range(10,1010)]
053| ys = [(1.0/x)*100.0 for x in xs]
054|
055| make_chart(xs, ys)
056|
057|
058| if __name__ == '__main__':
059| print(argv[0])
060| print()
061| main()
062| print()
063|
064| '''eof'''
065|