pizza.html


001| '''Pizza Buying Chart.'''
002| ####################################################################################################
003| from sys import argv
004| from os import path
005| from math import sqrt, pi
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 = 'pizza.png'
012| 
013| ##------------------------------------------------------------------------------------------------##
014| ymin, ymax = 0.0, 610
015| 
016| ##================================================================================================##
017| def make_chart (ds, ys1, ys2, ys3):
018|     fig, ax = plt.subplots()
019|     ax.set_title('Pizza Orders', fontsize=16, fontweight='bold')
020|     ax.set_xlabel('Pizza Diameter', fontsize=12, fontweight='bold', fontstyle='italic')
021|     ax.set_ylabel('Pizza Square Inches', fontsize=12, fontweight='bold', fontstyle='italic')
022| 
023|     ax.set_xlim(int(5), int(17))
024|     ax.set_ylim(ymin, ymax)
025| 
026|     ax.xaxis.set_major_locator(MultipleLocator(2))
027|     ax.xaxis.set_minor_locator(NullLocator())
028|     ax.xaxis.set_major_formatter(FormatStrFormatter('%d'))
029| 
030|     ax.yaxis.set_major_locator(MultipleLocator(100))
031|     ax.yaxis.set_minor_locator(MultipleLocator(10))
032|     ax.yaxis.set_major_formatter(FormatStrFormatter('%d'))
033| 
034|     ax.grid(which='major', axis='both', color='#3f3f3f', lw=1.2,ls='-',zorder=1, alpha=1.0)
035|     ax.grid(which='minor', axis='both', color='#7f7f7f', 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|     for tick in ax.xaxis.get_major_ticks():
040|         tick.label1.set_size(12)
041| 
042|     ax.plot(ds,y3s, label='3 Pizzas', color='#ff0000', lw=0.25, marker='o', ms=10, alpha=0.7, zorder=13)
043|     ax.plot(ds,y2s, label='2 Pizzas', color='#007f00', lw=0.25, marker='o', ms=10, alpha=0.7, zorder=12)
044|     ax.plot(ds,y1s, label='1 Pizza' , color='#0000bf', lw=0.25, marker='o', ms=10, alpha=0.7, zorder=11)
045|     ax.legend(loc='upper left', bbox_to_anchor=(0.0,1.0), shadow=True, fontsize=16)
046| 
047|     fig.set_figwidth(8.0)
048|     fig.set_figheight(6.0)
049|     fig.subplots_adjust(left=0.08, right=0.98, bottom=0.10, top=0.94)
050| 
051|     fn = path.join(ImgsPath, Filename)
052|     fig.savefig(fn)
053|     print(f'wrote: {fn}')
054|     print()
055| 
056| ##================================================================================================##
057| def main ():
058|     ds = [6, 8, 10, 12, 14, 16]
059|     xs = [d/2.0 for d in ds]
060| 
061|     y1s = [pi*(x*x)*1 for x in xs]
062|     y2s = [pi*(x*x)*2 for x in xs]
063|     y3s = [pi*(x*x)*3 for x in xs]
064| 
065|     make_chart(ds, ys1, ys2, ys3)
066| 
067| ####################################################################################################
068| if __name__ == '__main__':
069|     print(argv[0])
070|     print()
071|     main()
072|     print()
073| ####################################################################################################
074| '''eof'''
075|