Skip to content

Instantly share code, notes, and snippets.

@blaylockbk
Created July 10, 2020 21:53
Show Gist options
  • Save blaylockbk/a8409f1437e1959645a5128571d2cf91 to your computer and use it in GitHub Desktop.
Save blaylockbk/a8409f1437e1959645a5128571d2cf91 to your computer and use it in GitHub Desktop.
Side by side bar chart
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib import ticker
coins = ['penny', 'nickle', 'dime', 'quarter']
worth = np.array([.01, .05, .10, .25])
values = [worth*i for i in range(1,6)]
n = len(values)
w = .15
x = np.arange(0, len(coins))
T = n*w
for i, value in enumerate(values):
position = x + (w*(1-n)/2) + i*w
plt.bar(position, value, zorder=2, width=w, label=f'{i+1}x')
plt.xticks(x, coins);
plt.ylabel('Monetary Value')
plt.gca().yaxis.set_major_formatter(ticker.FormatStrFormatter('$%.2f'))
plt.legend()
@blaylockbk
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment