A new Pew Charitable Trusts analysis of data from the Bureau of Labor Statistics shows that in 2013, low-income Americans spent a median of 6,897 on housing. In 2014, that rose to 9,178 — the biggest jump in housing spending for the 19-year period of data that Pew studied.
The cost of other necessities, like transportation and food, also rose, albeit not as dramatically. 2014 was the first year that Pew studied in which median spending on these three categories was higher than the median income for those in the lower third of income groups.
import IPython.core.display as di
# This line will hide code by default when the notebook is exported as HTML
di.display_html('<script>jQuery(function() {if (jQuery("body.notebook_app").length == 0) { jQuery(".input_area").toggle(); jQuery(".prompt").toggle();}});</script>', raw=True)
# This line will add a button to toggle visibility of code blocks, for use with the HTML export version
di.display_html('''<button onclick="jQuery('.input_area').toggle(); jQuery('.prompt').toggle();">Toggle code</button>''', raw=True)
from IPython.display import Image
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from matplotlib.ticker import FuncFormatter
import matplotlib as mpl
import numpy as np
import pandas as pd
import seaborn as sns
from pandas import Series, DataFrame
%matplotlib inline
sns.set_style("darkgrid")
plt.style.use('fivethirtyeight')
Image('https://cdn2.vox-cdn.com/thumbor/PBFeR5h6uDVbac3CSVzXSpZJkAE=/800x0/filters:no_upscale()/cdn0.vox-cdn.com/uploads/chorus_asset/file/6268393/chart.0.png')
url = "https://raw.githubusercontent.com/voxmedia/data-projects/master/vox-data/pew-household-expenditures-2016.csv"
raw_data = pd.read_csv(url)
raw_data.head()
year | thirds | weighted_mean_total_expend | weighted_mean_food | weighted_mean_housing | weighted_mean_transportation | weighted_mean_healthcare | weighted_mean_entertainment | weighted_mean_apparal | weighted_mean_reading | ... | median_food | median_housing | median_transportation | median_healthcare | median_entertainment | median_apparal | median_reading | median_retirement_pension | median_cash_contrib | median_income | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1996 | Lower Third | 23465.69 | 4469.709 | 7748.817 | 4779.971 | 906.5408 | 992.0576 | 1022.189 | 90.83981 | ... | 3167.614 | 5674.843 | 1208.842 | 0.00000 | 386.1579 | 402.9474 | 0 | 420.8672 | 0 | 14548.08 |
1 | 1997 | Lower Third | 26339.62 | 4969.511 | 9298.430 | 5092.749 | 1200.3450 | 1134.4780 | 1087.907 | 95.18034 | ... | 3353.184 | 6136.958 | 1413.894 | 46.76302 | 462.1286 | 436.7694 | 0 | 501.3747 | 0 | 15696.40 |
2 | 1998 | Lower Third | 25917.10 | 4804.838 | 9145.672 | 4922.368 | 1136.4340 | 1189.4580 | 1066.689 | 92.84431 | ... | 3174.551 | 5999.362 | 1201.116 | 10.76119 | 442.2290 | 382.1732 | 0 | 522.7584 | 0 | 15794.67 |
3 | 1999 | Lower Third | 26129.84 | 4719.575 | 8987.732 | 5239.441 | 1090.0910 | 1218.5830 | 1103.091 | 86.00095 | ... | 3147.648 | 6141.948 | 1233.700 | 26.90297 | 467.2310 | 376.6416 | 0 | 593.6587 | 0 | 16141.78 |
4 | 2000 | Lower Third | 27817.75 | 4994.988 | 9332.954 | 5916.607 | 1200.1270 | 1290.1890 | 1113.315 | 81.42344 | ... | 3412.361 | 6336.492 | 1484.495 | 78.74680 | 514.7571 | 367.4851 | 0 | 580.8434 | 0 | 15880.60 |
5 rows × 24 columns
raw_data.dtypes
year int64 thirds object weighted_mean_total_expend float64 weighted_mean_food float64 weighted_mean_housing float64 weighted_mean_transportation float64 weighted_mean_healthcare float64 weighted_mean_entertainment float64 weighted_mean_apparal float64 weighted_mean_reading float64 weighted_mean_retirement_pension float64 weighted_mean_cash_contrib float64 weighted_mean_income float64 median_total_expend float64 median_food float64 median_housing float64 median_transportation float64 median_healthcare float64 median_entertainment float64 median_apparal float64 median_reading float64 median_retirement_pension float64 median_cash_contrib float64 median_income float64 dtype: object
raw_data.columns
Index([u'year', u'thirds', u'weighted_mean_total_expend', u'weighted_mean_food', u'weighted_mean_housing', u'weighted_mean_transportation', u'weighted_mean_healthcare', u'weighted_mean_entertainment', u'weighted_mean_apparal', u'weighted_mean_reading', u'weighted_mean_retirement_pension', u'weighted_mean_cash_contrib', u'weighted_mean_income', u'median_total_expend', u'median_food', u'median_housing', u'median_transportation', u'median_healthcare', u'median_entertainment', u'median_apparal', u'median_reading', u'median_retirement_pension', u'median_cash_contrib', u'median_income'], dtype='object')
# Copy raw_data into a new df
df = raw_data.copy()
df.columns
Index([u'year', u'thirds', u'weighted_mean_total_expend', u'weighted_mean_food', u'weighted_mean_housing', u'weighted_mean_transportation', u'weighted_mean_healthcare', u'weighted_mean_entertainment', u'weighted_mean_apparal', u'weighted_mean_reading', u'weighted_mean_retirement_pension', u'weighted_mean_cash_contrib', u'weighted_mean_income', u'median_total_expend', u'median_food', u'median_housing', u'median_transportation', u'median_healthcare', u'median_entertainment', u'median_apparal', u'median_reading', u'median_retirement_pension', u'median_cash_contrib', u'median_income'], dtype='object')
# Convert "thirds" column to category
df['thirds'] = df['thirds'].astype('category')
df.dtypes
year int64 thirds category weighted_mean_total_expend float64 weighted_mean_food float64 weighted_mean_housing float64 weighted_mean_transportation float64 weighted_mean_healthcare float64 weighted_mean_entertainment float64 weighted_mean_apparal float64 weighted_mean_reading float64 weighted_mean_retirement_pension float64 weighted_mean_cash_contrib float64 weighted_mean_income float64 median_total_expend float64 median_food float64 median_housing float64 median_transportation float64 median_healthcare float64 median_entertainment float64 median_apparal float64 median_reading float64 median_retirement_pension float64 median_cash_contrib float64 median_income float64 dtype: object
df.columns[2:]
Index([u'weighted_mean_total_expend', u'weighted_mean_food', u'weighted_mean_housing', u'weighted_mean_transportation', u'weighted_mean_healthcare', u'weighted_mean_entertainment', u'weighted_mean_apparal', u'weighted_mean_reading', u'weighted_mean_retirement_pension', u'weighted_mean_cash_contrib', u'weighted_mean_income', u'median_total_expend', u'median_food', u'median_housing', u'median_transportation', u'median_healthcare', u'median_entertainment', u'median_apparal', u'median_reading', u'median_retirement_pension', u'median_cash_contrib', u'median_income'], dtype='object')
# Save weighted_mean values in a separate dataframe
weighted_mean = df[['weighted_mean_total_expend', 'weighted_mean_food', 'weighted_mean_housing', 'weighted_mean_transportation',
'weighted_mean_healthcare', 'weighted_mean_entertainment', 'weighted_mean_apparal', 'weighted_mean_reading',
'weighted_mean_retirement_pension', 'weighted_mean_cash_contrib', 'weighted_mean_income']].copy()
# We'll be looking at median values for now
df = df[['thirds','median_total_expend', 'median_food','median_housing', 'median_transportation', 'median_healthcare',
'median_entertainment', 'median_apparal', 'median_reading','median_retirement_pension',
'median_cash_contrib', 'median_income']]
df
thirds | median_total_expend | median_food | median_housing | median_transportation | median_healthcare | median_entertainment | median_apparal | median_reading | median_retirement_pension | median_cash_contrib | median_income | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | Lower Third | 16186.45 | 3167.614 | 5674.843 | 1208.842 | 0.00000 | 386.1579 | 402.9474 | 0.00000 | 420.8672 | 0.00000 | 14548.08 |
1 | Lower Third | 17045.12 | 3353.184 | 6136.958 | 1413.894 | 46.76302 | 462.1286 | 436.7694 | 0.00000 | 501.3747 | 0.00000 | 15696.40 |
2 | Lower Third | 16194.86 | 3174.551 | 5999.362 | 1201.116 | 10.76119 | 442.2290 | 382.1732 | 0.00000 | 522.7584 | 0.00000 | 15794.67 |
3 | Lower Third | 16469.64 | 3147.648 | 6141.948 | 1233.700 | 26.90297 | 467.2310 | 376.6416 | 0.00000 | 593.6587 | 0.00000 | 16141.78 |
4 | Lower Third | 17796.78 | 3412.361 | 6336.492 | 1484.495 | 78.74680 | 514.7571 | 367.4851 | 0.00000 | 580.8434 | 0.00000 | 15880.60 |
5 | Lower Third | 17619.35 | 3320.342 | 6412.185 | 1423.004 | 0.00000 | 479.4166 | 339.9231 | 0.00000 | 647.9749 | 0.00000 | 16738.64 |
6 | Lower Third | 17852.68 | 3303.402 | 6403.517 | 1353.690 | 24.91778 | 465.9622 | 304.9294 | 0.00000 | 681.0090 | 0.00000 | 17162.80 |
7 | Lower Third | 17726.51 | 3239.312 | 6837.439 | 1495.067 | 0.00000 | 463.4707 | 254.1614 | 0.00000 | 667.7969 | 0.00000 | 17442.45 |
8 | Lower Third | 17417.29 | 3162.359 | 6510.437 | 1542.070 | 0.00000 | 452.4605 | 209.2021 | 0.00000 | 814.3961 | 0.00000 | 19867.88 |
9 | Lower Third | 17401.50 | 3074.680 | 6716.992 | 1560.991 | 0.00000 | 463.5671 | 236.5138 | 0.00000 | 819.7566 | 0.00000 | 20316.07 |
10 | Lower Third | 18651.59 | 3206.498 | 7186.978 | 1773.709 | 0.00000 | 497.5600 | 230.3519 | 0.00000 | 881.0958 | 0.00000 | 20686.98 |
11 | Lower Third | 19438.81 | 3782.088 | 7334.940 | 1865.196 | 0.00000 | 539.3339 | 224.7229 | 0.00000 | 946.0820 | 0.00000 | 20998.07 |
12 | Lower Third | 19507.30 | 3825.949 | 7273.666 | 1962.614 | 0.00000 | 549.5320 | 218.0683 | 0.00000 | 834.1111 | 0.00000 | 20138.39 |
13 | Lower Third | 18797.70 | 3578.644 | 7331.856 | 1623.482 | 0.00000 | 523.7744 | 183.2964 | 0.00000 | 775.0819 | 0.00000 | 19801.89 |
14 | Lower Third | 18262.34 | 3627.782 | 7070.955 | 1631.428 | 0.00000 | 530.7769 | 171.7293 | 0.00000 | 684.4130 | 0.00000 | 18868.76 |
15 | Lower Third | 18425.46 | 3626.741 | 7343.226 | 1864.702 | 0.00000 | 468.3719 | 167.6137 | 0.00000 | 648.9445 | 0.00000 | 18656.45 |
16 | Lower Third | 18364.26 | 3742.353 | 7073.458 | 1838.277 | 0.00000 | 468.8222 | 164.4990 | 0.00000 | 709.4020 | 0.00000 | 18711.76 |
17 | Lower Third | 17541.92 | 3466.667 | 6896.907 | 1668.381 | 0.00000 | 420.0000 | 121.7101 | 0.00000 | 620.7216 | 0.00000 | 17036.88 |
18 | Lower Third | 22659.60 | 4680.000 | 9178.000 | 2312.000 | 140.00000 | 672.0000 | 180.0000 | 0.00000 | 894.9000 | 0.00000 | 15525.50 |
19 | Middle Third | 27325.57 | 4365.264 | 8825.062 | 3015.674 | 610.01760 | 777.9124 | 696.3297 | 55.96492 | 2335.0350 | 0.00000 | 38547.23 |
20 | Middle Third | 29123.73 | 4533.262 | 9215.065 | 3139.280 | 687.69150 | 896.7496 | 770.2144 | 54.59618 | 2609.1010 | 0.00000 | 41261.48 |
21 | Middle Third | 28895.03 | 4476.887 | 9374.164 | 2964.573 | 622.39640 | 873.5389 | 709.7503 | 43.67694 | 2611.0620 | 0.00000 | 40947.13 |
22 | Middle Third | 29151.19 | 4465.893 | 9620.503 | 2980.849 | 677.95490 | 887.7980 | 715.6190 | 32.28357 | 2573.2690 | 0.00000 | 41699.61 |
23 | Middle Third | 29921.51 | 4567.314 | 9869.599 | 3281.117 | 692.97190 | 908.2131 | 661.4731 | 20.99915 | 2711.5150 | 0.00000 | 42023.23 |
24 | Middle Third | 29900.36 | 4558.060 | 9828.154 | 3183.878 | 700.44750 | 894.4519 | 618.0419 | 0.00000 | 2758.0120 | 0.00000 | 43931.20 |
25 | Middle Third | 31044.35 | 4523.119 | 10198.120 | 3201.759 | 792.81640 | 955.4454 | 609.8588 | 0.00000 | 2915.8870 | 0.00000 | 44856.71 |
26 | Middle Third | 30369.04 | 4460.282 | 10486.060 | 3239.311 | 749.19440 | 907.0078 | 498.3556 | 0.00000 | 2859.3150 | 0.00000 | 44976.59 |
27 | Middle Third | 30471.75 | 4694.886 | 10319.020 | 3201.280 | 744.37040 | 904.9210 | 462.1908 | 0.00000 | 3212.8340 | 0.00000 | 50455.66 |
28 | Middle Third | 31177.30 | 4499.016 | 10506.540 | 3453.102 | 695.50630 | 931.8647 | 402.0735 | 0.00000 | 3171.7920 | 0.00000 | 50384.77 |
29 | Middle Third | 32370.19 | 4791.317 | 11190.490 | 3662.594 | 718.69780 | 967.4778 | 460.7037 | 0.00000 | 3259.9400 | 0.00000 | 51008.88 |
30 | Middle Third | 33350.88 | 5258.505 | 11160.730 | 3671.965 | 750.57300 | 959.5004 | 443.4520 | 0.00000 | 3322.0720 | 0.00000 | 50670.42 |
31 | Middle Third | 33731.34 | 5480.782 | 11252.320 | 4001.552 | 732.70940 | 1023.7990 | 409.9683 | 0.00000 | 3336.4440 | 0.00000 | 51324.77 |
32 | Middle Third | 32848.42 | 5106.114 | 11466.940 | 3316.792 | 765.39660 | 999.4018 | 353.5006 | 0.00000 | 3172.7730 | 0.00000 | 50188.30 |
33 | Middle Third | 31616.44 | 5117.534 | 11274.030 | 3288.616 | 768.48870 | 996.0300 | 339.1654 | 0.00000 | 3038.5360 | 0.00000 | 48359.19 |
34 | Middle Third | 32036.43 | 5265.864 | 11154.690 | 3666.550 | 807.89810 | 945.8694 | 335.2274 | 0.00000 | 2969.2770 | 0.00000 | 47560.39 |
35 | Middle Third | 32238.21 | 5303.123 | 11025.550 | 3678.609 | 863.61990 | 970.5442 | 359.1560 | 0.00000 | 3041.4840 | 0.00000 | 48076.48 |
36 | Middle Third | 30669.33 | 5192.965 | 10743.960 | 3407.883 | 770.83070 | 900.6548 | 271.8192 | 0.00000 | 2986.3610 | 0.00000 | 46655.54 |
37 | Middle Third | 31755.00 | 5584.000 | 11520.000 | 3632.000 | 1104.00000 | 1020.0000 | 400.0000 | 0.00000 | 2708.2000 | 0.00000 | 39499.00 |
38 | Highest Third | 47016.83 | 6366.123 | 13662.440 | 4992.071 | 1203.24600 | 1595.0000 | 1354.3510 | 147.37410 | 5887.5090 | 0.00000 | 81425.81 |
39 | Highest Third | 49809.49 | 6546.822 | 14612.070 | 5242.959 | 1270.85400 | 1749.4870 | 1470.7430 | 148.54140 | 6026.9280 | 0.00000 | 82539.48 |
40 | Highest Third | 49058.76 | 6360.455 | 14457.070 | 5030.855 | 1226.77600 | 1754.3570 | 1310.3080 | 147.06940 | 6264.9120 | 0.00000 | 85443.02 |
41 | Highest Third | 49965.54 | 6472.855 | 14888.100 | 5063.139 | 1291.34300 | 1795.4270 | 1296.6970 | 134.51490 | 6573.7410 | 0.00000 | 87770.95 |
42 | Highest Third | 50504.26 | 6630.480 | 15289.130 | 5423.318 | 1284.44800 | 1795.4270 | 1259.9490 | 120.74510 | 6464.2370 | 0.00000 | 88865.77 |
43 | Highest Third | 52188.49 | 6611.597 | 15734.320 | 5614.832 | 1333.94100 | 1756.5010 | 1220.6330 | 103.00700 | 6642.2340 | 33.88121 | 92706.29 |
44 | Highest Third | 52938.49 | 6581.393 | 15965.810 | 5460.777 | 1504.31800 | 1875.3160 | 1158.7320 | 99.67112 | 6803.7370 | 254.10780 | 95290.43 |
45 | Highest Third | 51701.70 | 6503.541 | 15544.130 | 5317.541 | 1480.11600 | 1784.1140 | 1031.5960 | 73.09182 | 7041.7650 | 241.23450 | 96087.04 |
46 | Highest Third | 52938.05 | 6767.447 | 16032.390 | 5480.610 | 1605.50500 | 1731.9980 | 973.0333 | 58.38200 | 7257.6120 | 170.28080 | 101549.40 |
47 | Highest Third | 53401.27 | 6557.350 | 15899.640 | 5543.884 | 1513.68900 | 1680.8250 | 922.4044 | 29.17775 | 7349.7590 | 189.21100 | 103658.30 |
48 | Highest Third | 55723.07 | 6852.968 | 17165.820 | 5989.148 | 1542.34500 | 1759.8880 | 944.4423 | 19.47580 | 7551.2650 | 224.72250 | 104917.70 |
49 | Highest Third | 56839.99 | 7564.158 | 17411.500 | 5946.156 | 1573.05700 | 1836.1350 | 898.8898 | 11.63002 | 7553.1870 | 179.77800 | 106743.20 |
50 | Highest Third | 57435.91 | 7798.121 | 17205.590 | 6454.820 | 1744.54600 | 1962.6140 | 872.2731 | 0.00000 | 7635.6610 | 226.79100 | 106784.80 |
51 | Highest Third | 54960.55 | 7413.151 | 16676.700 | 5234.858 | 1822.05300 | 1920.2480 | 785.5560 | 0.00000 | 7638.7940 | 218.21000 | 106470.70 |
52 | Highest Third | 53413.72 | 7285.616 | 16514.410 | 5237.744 | 1793.46700 | 1807.4510 | 718.8544 | 0.00000 | 7360.4080 | 148.46260 | 102044.70 |
53 | Highest Third | 53114.79 | 7263.260 | 16299.730 | 5656.962 | 1868.89300 | 1699.8230 | 712.3582 | 0.00000 | 7157.8010 | 104.75860 | 101555.80 |
54 | Highest Third | 54837.12 | 7484.706 | 16449.900 | 5913.740 | 2023.09300 | 1725.5790 | 806.0452 | 0.00000 | 7288.7450 | 121.71010 | 102811.90 |
55 | Highest Third | 53065.41 | 7413.333 | 16280.760 | 5554.038 | 2000.00000 | 1582.2310 | 588.2656 | 0.00000 | 7171.5650 | 121.71010 | 100466.40 |
56 | Highest Third | 56812.00 | 8237.334 | 17764.000 | 6030.000 | 3082.66700 | 1960.0000 | 740.0000 | 0.00000 | 7738.0000 | 200.00000 | 95000.00 |
x = range(1996, 2015)
df.index = 3*x
df['housing+food'] = df['median_housing'] + df['median_food']
df['housing+food+transport'] = df['median_housing'] + df['median_food'] + df['median_transportation']
df
thirds | median_total_expend | median_food | median_housing | median_transportation | median_healthcare | median_entertainment | median_apparal | median_reading | median_retirement_pension | median_cash_contrib | median_income | housing+food | housing+food+transport | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1996 | Lower Third | 16186.45 | 3167.614 | 5674.843 | 1208.842 | 0.00000 | 386.1579 | 402.9474 | 0.00000 | 420.8672 | 0.00000 | 14548.08 | 8842.457 | 10051.299 |
1997 | Lower Third | 17045.12 | 3353.184 | 6136.958 | 1413.894 | 46.76302 | 462.1286 | 436.7694 | 0.00000 | 501.3747 | 0.00000 | 15696.40 | 9490.142 | 10904.036 |
1998 | Lower Third | 16194.86 | 3174.551 | 5999.362 | 1201.116 | 10.76119 | 442.2290 | 382.1732 | 0.00000 | 522.7584 | 0.00000 | 15794.67 | 9173.913 | 10375.029 |
1999 | Lower Third | 16469.64 | 3147.648 | 6141.948 | 1233.700 | 26.90297 | 467.2310 | 376.6416 | 0.00000 | 593.6587 | 0.00000 | 16141.78 | 9289.596 | 10523.296 |
2000 | Lower Third | 17796.78 | 3412.361 | 6336.492 | 1484.495 | 78.74680 | 514.7571 | 367.4851 | 0.00000 | 580.8434 | 0.00000 | 15880.60 | 9748.853 | 11233.348 |
2001 | Lower Third | 17619.35 | 3320.342 | 6412.185 | 1423.004 | 0.00000 | 479.4166 | 339.9231 | 0.00000 | 647.9749 | 0.00000 | 16738.64 | 9732.527 | 11155.531 |
2002 | Lower Third | 17852.68 | 3303.402 | 6403.517 | 1353.690 | 24.91778 | 465.9622 | 304.9294 | 0.00000 | 681.0090 | 0.00000 | 17162.80 | 9706.919 | 11060.609 |
2003 | Lower Third | 17726.51 | 3239.312 | 6837.439 | 1495.067 | 0.00000 | 463.4707 | 254.1614 | 0.00000 | 667.7969 | 0.00000 | 17442.45 | 10076.751 | 11571.818 |
2004 | Lower Third | 17417.29 | 3162.359 | 6510.437 | 1542.070 | 0.00000 | 452.4605 | 209.2021 | 0.00000 | 814.3961 | 0.00000 | 19867.88 | 9672.796 | 11214.866 |
2005 | Lower Third | 17401.50 | 3074.680 | 6716.992 | 1560.991 | 0.00000 | 463.5671 | 236.5138 | 0.00000 | 819.7566 | 0.00000 | 20316.07 | 9791.672 | 11352.663 |
2006 | Lower Third | 18651.59 | 3206.498 | 7186.978 | 1773.709 | 0.00000 | 497.5600 | 230.3519 | 0.00000 | 881.0958 | 0.00000 | 20686.98 | 10393.476 | 12167.185 |
2007 | Lower Third | 19438.81 | 3782.088 | 7334.940 | 1865.196 | 0.00000 | 539.3339 | 224.7229 | 0.00000 | 946.0820 | 0.00000 | 20998.07 | 11117.028 | 12982.224 |
2008 | Lower Third | 19507.30 | 3825.949 | 7273.666 | 1962.614 | 0.00000 | 549.5320 | 218.0683 | 0.00000 | 834.1111 | 0.00000 | 20138.39 | 11099.615 | 13062.229 |
2009 | Lower Third | 18797.70 | 3578.644 | 7331.856 | 1623.482 | 0.00000 | 523.7744 | 183.2964 | 0.00000 | 775.0819 | 0.00000 | 19801.89 | 10910.500 | 12533.982 |
2010 | Lower Third | 18262.34 | 3627.782 | 7070.955 | 1631.428 | 0.00000 | 530.7769 | 171.7293 | 0.00000 | 684.4130 | 0.00000 | 18868.76 | 10698.737 | 12330.165 |
2011 | Lower Third | 18425.46 | 3626.741 | 7343.226 | 1864.702 | 0.00000 | 468.3719 | 167.6137 | 0.00000 | 648.9445 | 0.00000 | 18656.45 | 10969.967 | 12834.669 |
2012 | Lower Third | 18364.26 | 3742.353 | 7073.458 | 1838.277 | 0.00000 | 468.8222 | 164.4990 | 0.00000 | 709.4020 | 0.00000 | 18711.76 | 10815.811 | 12654.088 |
2013 | Lower Third | 17541.92 | 3466.667 | 6896.907 | 1668.381 | 0.00000 | 420.0000 | 121.7101 | 0.00000 | 620.7216 | 0.00000 | 17036.88 | 10363.574 | 12031.955 |
2014 | Lower Third | 22659.60 | 4680.000 | 9178.000 | 2312.000 | 140.00000 | 672.0000 | 180.0000 | 0.00000 | 894.9000 | 0.00000 | 15525.50 | 13858.000 | 16170.000 |
1996 | Middle Third | 27325.57 | 4365.264 | 8825.062 | 3015.674 | 610.01760 | 777.9124 | 696.3297 | 55.96492 | 2335.0350 | 0.00000 | 38547.23 | 13190.326 | 16206.000 |
1997 | Middle Third | 29123.73 | 4533.262 | 9215.065 | 3139.280 | 687.69150 | 896.7496 | 770.2144 | 54.59618 | 2609.1010 | 0.00000 | 41261.48 | 13748.327 | 16887.607 |
1998 | Middle Third | 28895.03 | 4476.887 | 9374.164 | 2964.573 | 622.39640 | 873.5389 | 709.7503 | 43.67694 | 2611.0620 | 0.00000 | 40947.13 | 13851.051 | 16815.624 |
1999 | Middle Third | 29151.19 | 4465.893 | 9620.503 | 2980.849 | 677.95490 | 887.7980 | 715.6190 | 32.28357 | 2573.2690 | 0.00000 | 41699.61 | 14086.396 | 17067.245 |
2000 | Middle Third | 29921.51 | 4567.314 | 9869.599 | 3281.117 | 692.97190 | 908.2131 | 661.4731 | 20.99915 | 2711.5150 | 0.00000 | 42023.23 | 14436.913 | 17718.030 |
2001 | Middle Third | 29900.36 | 4558.060 | 9828.154 | 3183.878 | 700.44750 | 894.4519 | 618.0419 | 0.00000 | 2758.0120 | 0.00000 | 43931.20 | 14386.214 | 17570.092 |
2002 | Middle Third | 31044.35 | 4523.119 | 10198.120 | 3201.759 | 792.81640 | 955.4454 | 609.8588 | 0.00000 | 2915.8870 | 0.00000 | 44856.71 | 14721.239 | 17922.998 |
2003 | Middle Third | 30369.04 | 4460.282 | 10486.060 | 3239.311 | 749.19440 | 907.0078 | 498.3556 | 0.00000 | 2859.3150 | 0.00000 | 44976.59 | 14946.342 | 18185.653 |
2004 | Middle Third | 30471.75 | 4694.886 | 10319.020 | 3201.280 | 744.37040 | 904.9210 | 462.1908 | 0.00000 | 3212.8340 | 0.00000 | 50455.66 | 15013.906 | 18215.186 |
2005 | Middle Third | 31177.30 | 4499.016 | 10506.540 | 3453.102 | 695.50630 | 931.8647 | 402.0735 | 0.00000 | 3171.7920 | 0.00000 | 50384.77 | 15005.556 | 18458.658 |
2006 | Middle Third | 32370.19 | 4791.317 | 11190.490 | 3662.594 | 718.69780 | 967.4778 | 460.7037 | 0.00000 | 3259.9400 | 0.00000 | 51008.88 | 15981.807 | 19644.401 |
2007 | Middle Third | 33350.88 | 5258.505 | 11160.730 | 3671.965 | 750.57300 | 959.5004 | 443.4520 | 0.00000 | 3322.0720 | 0.00000 | 50670.42 | 16419.235 | 20091.200 |
2008 | Middle Third | 33731.34 | 5480.782 | 11252.320 | 4001.552 | 732.70940 | 1023.7990 | 409.9683 | 0.00000 | 3336.4440 | 0.00000 | 51324.77 | 16733.102 | 20734.654 |
2009 | Middle Third | 32848.42 | 5106.114 | 11466.940 | 3316.792 | 765.39660 | 999.4018 | 353.5006 | 0.00000 | 3172.7730 | 0.00000 | 50188.30 | 16573.054 | 19889.846 |
2010 | Middle Third | 31616.44 | 5117.534 | 11274.030 | 3288.616 | 768.48870 | 996.0300 | 339.1654 | 0.00000 | 3038.5360 | 0.00000 | 48359.19 | 16391.564 | 19680.180 |
2011 | Middle Third | 32036.43 | 5265.864 | 11154.690 | 3666.550 | 807.89810 | 945.8694 | 335.2274 | 0.00000 | 2969.2770 | 0.00000 | 47560.39 | 16420.554 | 20087.104 |
2012 | Middle Third | 32238.21 | 5303.123 | 11025.550 | 3678.609 | 863.61990 | 970.5442 | 359.1560 | 0.00000 | 3041.4840 | 0.00000 | 48076.48 | 16328.673 | 20007.282 |
2013 | Middle Third | 30669.33 | 5192.965 | 10743.960 | 3407.883 | 770.83070 | 900.6548 | 271.8192 | 0.00000 | 2986.3610 | 0.00000 | 46655.54 | 15936.925 | 19344.808 |
2014 | Middle Third | 31755.00 | 5584.000 | 11520.000 | 3632.000 | 1104.00000 | 1020.0000 | 400.0000 | 0.00000 | 2708.2000 | 0.00000 | 39499.00 | 17104.000 | 20736.000 |
1996 | Highest Third | 47016.83 | 6366.123 | 13662.440 | 4992.071 | 1203.24600 | 1595.0000 | 1354.3510 | 147.37410 | 5887.5090 | 0.00000 | 81425.81 | 20028.563 | 25020.634 |
1997 | Highest Third | 49809.49 | 6546.822 | 14612.070 | 5242.959 | 1270.85400 | 1749.4870 | 1470.7430 | 148.54140 | 6026.9280 | 0.00000 | 82539.48 | 21158.892 | 26401.851 |
1998 | Highest Third | 49058.76 | 6360.455 | 14457.070 | 5030.855 | 1226.77600 | 1754.3570 | 1310.3080 | 147.06940 | 6264.9120 | 0.00000 | 85443.02 | 20817.525 | 25848.380 |
1999 | Highest Third | 49965.54 | 6472.855 | 14888.100 | 5063.139 | 1291.34300 | 1795.4270 | 1296.6970 | 134.51490 | 6573.7410 | 0.00000 | 87770.95 | 21360.955 | 26424.094 |
2000 | Highest Third | 50504.26 | 6630.480 | 15289.130 | 5423.318 | 1284.44800 | 1795.4270 | 1259.9490 | 120.74510 | 6464.2370 | 0.00000 | 88865.77 | 21919.610 | 27342.928 |
2001 | Highest Third | 52188.49 | 6611.597 | 15734.320 | 5614.832 | 1333.94100 | 1756.5010 | 1220.6330 | 103.00700 | 6642.2340 | 33.88121 | 92706.29 | 22345.917 | 27960.749 |
2002 | Highest Third | 52938.49 | 6581.393 | 15965.810 | 5460.777 | 1504.31800 | 1875.3160 | 1158.7320 | 99.67112 | 6803.7370 | 254.10780 | 95290.43 | 22547.203 | 28007.980 |
2003 | Highest Third | 51701.70 | 6503.541 | 15544.130 | 5317.541 | 1480.11600 | 1784.1140 | 1031.5960 | 73.09182 | 7041.7650 | 241.23450 | 96087.04 | 22047.671 | 27365.212 |
2004 | Highest Third | 52938.05 | 6767.447 | 16032.390 | 5480.610 | 1605.50500 | 1731.9980 | 973.0333 | 58.38200 | 7257.6120 | 170.28080 | 101549.40 | 22799.837 | 28280.447 |
2005 | Highest Third | 53401.27 | 6557.350 | 15899.640 | 5543.884 | 1513.68900 | 1680.8250 | 922.4044 | 29.17775 | 7349.7590 | 189.21100 | 103658.30 | 22456.990 | 28000.874 |
2006 | Highest Third | 55723.07 | 6852.968 | 17165.820 | 5989.148 | 1542.34500 | 1759.8880 | 944.4423 | 19.47580 | 7551.2650 | 224.72250 | 104917.70 | 24018.788 | 30007.936 |
2007 | Highest Third | 56839.99 | 7564.158 | 17411.500 | 5946.156 | 1573.05700 | 1836.1350 | 898.8898 | 11.63002 | 7553.1870 | 179.77800 | 106743.20 | 24975.658 | 30921.814 |
2008 | Highest Third | 57435.91 | 7798.121 | 17205.590 | 6454.820 | 1744.54600 | 1962.6140 | 872.2731 | 0.00000 | 7635.6610 | 226.79100 | 106784.80 | 25003.711 | 31458.531 |
2009 | Highest Third | 54960.55 | 7413.151 | 16676.700 | 5234.858 | 1822.05300 | 1920.2480 | 785.5560 | 0.00000 | 7638.7940 | 218.21000 | 106470.70 | 24089.851 | 29324.709 |
2010 | Highest Third | 53413.72 | 7285.616 | 16514.410 | 5237.744 | 1793.46700 | 1807.4510 | 718.8544 | 0.00000 | 7360.4080 | 148.46260 | 102044.70 | 23800.026 | 29037.770 |
2011 | Highest Third | 53114.79 | 7263.260 | 16299.730 | 5656.962 | 1868.89300 | 1699.8230 | 712.3582 | 0.00000 | 7157.8010 | 104.75860 | 101555.80 | 23562.990 | 29219.952 |
2012 | Highest Third | 54837.12 | 7484.706 | 16449.900 | 5913.740 | 2023.09300 | 1725.5790 | 806.0452 | 0.00000 | 7288.7450 | 121.71010 | 102811.90 | 23934.606 | 29848.346 |
2013 | Highest Third | 53065.41 | 7413.333 | 16280.760 | 5554.038 | 2000.00000 | 1582.2310 | 588.2656 | 0.00000 | 7171.5650 | 121.71010 | 100466.40 | 23694.093 | 29248.131 |
2014 | Highest Third | 56812.00 | 8237.334 | 17764.000 | 6030.000 | 3082.66700 | 1960.0000 | 740.0000 | 0.00000 | 7738.0000 | 200.00000 | 95000.00 | 26001.334 | 32031.334 |
# Create three data frames for lower, middle and highest thirds. Reset index and drop old one.
lower = df[df['thirds'] == 'Lower Third'].reset_index(drop=True)
middle = df[df['thirds'] == 'Middle Third'].reset_index(drop=True)
highest = df[df['thirds'] == 'Highest Third'].reset_index(drop=True)
# Set index to years
lower.index = range(1996, 2015)
middle.index = range(1996, 2015)
highest.index = range(1996, 2015)
# ==== Design the figure ==== #
# Set general plot properties
sns.set_context({"figure.figsize": (3, 8)})
sns.set_color_codes(palette='muted')
fig, ax = plt.subplots(figsize=(11, 8))
ax.grid(True,linestyle='-',color='0.9')
ax.set_ylim([0,df['median_income'].max()])
ax.axes.get_xaxis().set_visible(False)
ylim = df['median_income'].max() + 10000
# Bigger font sizes for plots
mpl.rcParams.update({'font.size': 18})
mpl.rc('xtick', labelsize=10)
mpl.rc('ytick', labelsize=18)
mpl.rc('labelsize: large')
# ==== Make legend ==== #
leg1 = plt.Rectangle((0,0),1,1,fc="navy", edgecolor = 'none')
leg2 = plt.Rectangle((0,0),1,1,fc='skyblue', edgecolor = 'none')
leg3 = plt.Rectangle((0,0),1,1,fc='g', edgecolor='none')
leg4 = plt.Rectangle((0,0),1,1,fc='r', edgecolor='none')
l = plt.legend([leg1, leg2, leg3, leg4], ['Housing', 'Food', 'Transportation', 'Income'],
bbox_to_anchor=(.8,1.01), ncol = 4, prop={'size':16})
l.draw_frame(False)
# Format y axis ticks
def thousands(x, pos):
'The two args are the value and tick position'
return '$%iK' % (x*1e-3)
formatter = FuncFormatter(thousands)
ax.yaxis.set_major_formatter(formatter)
# ==== Plot the data ==== #
# Lower plot
ax1=fig.add_subplot(131)
# Bar 1 - background - "total" (top) series
top_plot = sns.barplot(x = lower.index, y = lower['housing+food+transport'], color='g')
# Bar 2 - overlay - "middle" series
middle_plot = sns.barplot(x = lower.index, y = lower['housing+food'], color = "skyblue")
# Bar 3 - overlay - "bottom" series
bottom_plot = sns.barplot(x = lower.index, y = lower['median_housing'], color = "navy")
# Line
income_line = plt.plot(lower['median_income'],'--', color='r')
# Set axes
ax1.set_ylim([0,ylim])
ax1.axes.get_yaxis().set_visible(False)
ax1.set_axis_off()
plt.xticks(rotation=90)
# Middle plot
ax2=fig.add_subplot(132)
top_plot = sns.barplot(x = middle.index, y = middle['housing+food+transport'], color='g')
# Bar 2 - overlay - "middle" series
middle_plot = sns.barplot(x = middle.index, y = middle['housing+food'], color = "skyblue")
# Bar 3 - overlay - "bottom" series
bottom_plot = sns.barplot(x = middle.index, y = middle['median_housing'], color = "navy")
# Line
income_line = plt.plot(middle['median_income'],'--', color='r')
# Set axes
ax2.set_ylim([0,ylim])
ax2.axes.get_yaxis().set_visible(False)
ax2.set_axis_off()
plt.xticks(rotation=90)
# Highest plot
ax3=fig.add_subplot(133)
top_plot = sns.barplot(x = highest.index, y = highest['housing+food+transport'], color='g')
# Bar 2 - overlay - "middle" series
middle_plot = sns.barplot(x = highest.index, y = highest['housing+food'], color = "skyblue")
# Bar 3 - overlay - "bottom" series
bottom_plot = sns.barplot(x = highest.index, y = highest['median_housing'], color = "navy")
# Line
income_line = plt.plot(highest['median_income'],'--', color='r')
# Set axes
ax3.set_ylim([0,ylim])
ax3.axes.get_yaxis().set_visible(False)
ax3.set_axis_off()
plt.xticks(rotation=90)
# ==== Add text ==== #
# Title
title = ax.annotate("Rising rent costs are devastating to low-income families",
(0,0), (-75, 550), textcoords='offset points', color='gray', fontsize=26, fontweight='heavy')
# Subtitle
ax.annotate("Median incomes and costs of housing, food and transportation across income",
(0,0), (-75, 525), textcoords='offset points', color='gray', fontsize=16, style='italic')
ax.annotate("groups from 1996 to 2014. Figures adjusted for inflation.",
(0,0), (-75, 505), textcoords='offset points', color='gray', fontsize=16, style='italic')
# Plot 1 annotations
ax1.annotate("'96", (0,0), (0, -5), xycoords='axes fraction', textcoords='offset points',
va='top', color='gray')
ax1.annotate("'14", (0,0), (198, -5), xycoords='axes fraction', textcoords='offset points',
va='top', color='gray')
lower_annotate = ax1.annotate("Lower", (0,0), (70, -20), xycoords='axes fraction', textcoords='offset points',
va='top', color='gray', fontsize=22, fontweight='bold')
# Plot 2 annotations
ax2.annotate("'96", (0,0), (0, -5), xycoords='axes fraction', textcoords='offset points',
va='top', color='gray')
ax2.annotate("'14", (0,0), (198, -5), xycoords='axes fraction', textcoords='offset points',
va='top', color='gray')
ax2.annotate("Middle", (0,0), (70, -20), xycoords='axes fraction', textcoords='offset points',
va='top', color='gray', fontsize=22, fontweight='bold')
# Plot 3 annotations
ax3.annotate("'96", (0,0), (0, -5), xycoords='axes fraction', textcoords='offset points',
va='top', color='gray')
ax3.annotate("'14", (0,0), (198, -5), xycoords='axes fraction', textcoords='offset points',
va='top', color='gray')
ax3.annotate("Upper", (0,0), (70, -20), xycoords='axes fraction', textcoords='offset points',
va='top', color='gray', fontsize=22, fontweight='bold')
# Source annotations
source_annotate = ax.annotate("Vox Media, March 2016. Data visualization by Will Geary.",
(0,0), (-75, -75), textcoords='offset points', color='gray', fontsize=14, style='italic')
#ax.set_position([0.0,0.0,0.0,0.0])
fig.tight_layout()
fig.savefig('/Users/Will/personal-website/assets/2016-05-26-fig3.png',
bbox_extra_artists=(l,title, lower_annotate, source_annotate),
bbox_inches='tight')