beer-1.html


001| from os import path
002| import numpy as np
003| import matplotlib.pyplot as plt
004| 
005| BasePath = r'C:\CJS\prj\Python\charts'
006| ImgsPath = path.join(BasePath,'img')
007| 
008| data = [
009|  ('Cyg.X1' ,6.5, 45),
010|  ('Angry',  6.0, 48),
011|  ('Livid',  6.0, 81),
012|  ('N.W.P.' ,6.5,115),
013|  ('W.W.',  10.1, 46),
014|  ('Ele.115',5.5, 46)
015| ]
016| N = len(data)
017| xs = np.arange(N)
018| bs = [d[0] for d in data]
019| abv = [d[1] for d in data]
020| ibu = [d[2] for d in data]
021| 
022| fig, ax1 = plt.subplots()
023| fig.set_figwidth(8.0)
024| fig.set_figheight(3.0)
025| fig.subplots_adjust(left=0.08, right=0.93, bottom=0.11, top=0.90)
026| 
027| plt.title('A Selection of Flat Earth Beers', fontweight='bold')
028| plt.xlim(-0.5, N-0.5)
029| plt.xticks(xs, bs)
030| ax1.grid(axis='both', zorder=0)
031| ax1.set_ylabel('IBU', color='g', fontweight='bold')
032| ax1.set_ylim(0.0, 120.0)
033| ax1.set_yticks(np.arange(0, 121, 10))
034| 
035| ax2 = ax1.twinx()
036| ax2.set_ylabel('ABV', color='r', fontweight='bold')
037| ax2.set_ylim(0.0, 12.0)
038| ax2.set_yticks(np.arange(0.0, 12.0, 1.0))
039| 
040| p1 = ax1.bar([x-0.10 for x in xs], ibu, width=0.5, color='g', alpha=0.95, zorder=8)
041| p2 = ax2.bar([x+0.10 for x in xs], abv, width=0.5, color='r', alpha=0.95, zorder=9)
042| plt.legend((p1[0],p2[0]), ('IBU','ABV'), loc='upper left')
043| 
044| fn = path.join(ImgsPath, 'beer-1.png')
045| plt.savefig(fn)
046| print('wrote: %s' % fn)
047| print()
048| 
049| '''eof'''
050|