Created
July 10, 2020 21:53
-
-
Save blaylockbk/a8409f1437e1959645a5128571d2cf91 to your computer and use it in GitHub Desktop.
Side by side bar chart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Author
blaylockbk
commented
Jul 10, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment