Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joferkington/2d79188ef0c2d5f4bbd0 to your computer and use it in GitHub Desktop.
Save joferkington/2d79188ef0c2d5f4bbd0 to your computer and use it in GitHub Desktop.
import random
import matplotlib.pyplot as plt
from mpldatacursor import datacursor
def main():
accounts = generate_accounts()
plot(accounts)
datacursor(formatter='Account #\n{label}'.format, bbox=dict(alpha=1))
plt.show()
def plot(accounts):
fig, ax = plt.subplots()
for i, account in enumerate(accounts):
ax.bar([i], [account.balance], align='center', label=account.number)
ax.set(xticks=range(len(accounts)), xticklabels=[x.owner for x in accounts],
ylabel='Balance ($)')
ax.grid(axis='y')
def generate_accounts():
names = ['Mark', 'Nancy', 'Sam', 'John', 'Patricia', 'Anna']
accounts = [random.randint(100000, 9999999) for _ in names]
balances = [random.randint(-1000, 10000) for _ in names]
return [BankAccount(*item) for item in zip(names, accounts, balances)]
class BankAccount:
def __init__(self, owner, number, balance):
self.owner, self.number, self.balance = owner, number, balance
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment