import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
bin_sizes = np.array((1, 4, 5, 10, 20, 20, 40, 0))[::-1]
bin_edges = np.cumsum(bin_sizes)
net_worth_2007 = np.array((34.6, 27.3, 11.2, 12, 10.9, 4, 0.2))[::-1]
net_worth_2013 = np.array((36.7, 28.2, 12.2, 11.8, 9.3, 2.7, -0.9))[::-1]
fake_data = bin_edges[:-1]+1
plt.grid(True, which='both')
bar_list = plt.hist(fake_data, bins=bin_edges, weights=net_worth_2013,
normed=True)
# Colors from pie chart template
bar_list[2][0].set_color('#008000')
bar_list[2][1].set_color('#bc514c')
bar_list[2][2].set_color('#ffa500')
bar_list[2][3].set_color('#96b2da')
bar_list[2][4].set_color('#588cdb')
bar_list[2][5].set_color('#385f96')
bar_list[2][6].set_color('#273f64')
plt.title('US Distribution of Wealth, 2013')
plt.figtext(0.01, 0.01, 'Edward N. Wolff, 2014', horizontalalignment='left',
size='small')
plt.xlabel('% of population')
plt.ylabel('% of wealth / % of population')
plt.margins(0, 0)
def y_to_percent(y, position):
s = f'{100 * y:.0f}%'
return s
def x_to_percent(y, position):
s = f'{y:.0f}%'
return s
# Set the formatter
plt.gca().yaxis.set_major_formatter(mpl.ticker.FuncFormatter(y_to_percent))
plt.gca().xaxis.set_major_formatter(mpl.ticker.FuncFormatter(x_to_percent))