@beer-1.py
import numpy as np
import matplotlib.pyplot as plt
data = [
('Cyg.X1' ,6.5, 45),
('Angry', 6.0, 48),
('Livid', 6.0, 81),
('N.W.P.' ,6.5,115),
('W.W.', 10.1, 46),
('Ele.115',5.5, 46)
]
N = len(data)
xs = np.arange(N)
bs = [d[0] for d in data]
abv = [d[1] for d in data]
ibu = [d[2] for d in data]
fig, ax1 = plt.subplots()
plt.title('A Set of Flat Earth Beers')
plt.xlim(-0.5, N-0.5)
plt.xticks(xs, bs)
ax1.grid(axes=ax1, axis='both', zorder=0)
ax1.set_ylabel('IBU', color='g')
ax1.set_ylim(0.0, 120.0)
ax1.set_yticks(np.arange(0, 121, 10))
p1 = ax1.bar([x-0.10 for x in xs], ibu, width=0.5, color='g', alpha=0.95, zorder=8)
ax2 = ax1.twinx()
ax2.set_ylabel('ABV', color='r')
ax2.set_ylim(0.0, 12.0)
ax2.set_yticks(np.arange(0.0, 12.0, 1.0))
p2 = ax2.bar([x+0.10 for x in xs], abv, width=0.5, color='r', alpha=0.95, zorder=9)
plt.legend((p1[0],p2[0]), ('IBU','ABV'), loc='upper left')
plt.savefig('beer-1.png')