# Copyright (C) 2020 Jonathan A. Poritz # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # # # following variables need to updated for new runs with more data # # get book prices from https://data.bls.gov/timeseries/CUUR0000SEEA, choose # "From: 1980" and "To: " # and uncheck 'include graphs' but check 'include annual averages' book_price_CSV_filename = 'SeriesReport-20200413150436_1d1108.csv' # get CPI info from https://data.bls.gov/timeseries/CUUR0000SA0 # "From: 1980" and "To: " # and uncheck 'include graphs' but check 'include annual averages' CPI_CSV_filename = 'SeriesReport-20200413142351_d3e032.csv' count = 0 years = [] b = [] month_frac = 1./12. # get the book price info with open(book_price_CSV_filename,'r') as f: for line in f: count += 1 if count < 13: continue # first 12 lines are headers to be skipped nums = line.split(",") month = -1 for loc in nums: month += 1 if month==0: year = float(loc) continue if month==12 or not loc: break years.append(year+month*month_frac) b.append(float(loc)) ending_year = int(max(years)) month_names = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] last_month_name = month_names[int(12*(max(years)-ending_year))-1] inc_b = [] # percent increase over the amount of the first year's value for i in range(len(b)): inc_b.append(100.*((b[i]/b[0])-1)) count = 0 c = [] # get the CPI info with open(CPI_CSV_filename,'r') as f: for line in f: count += 1 if count < 13: continue # first 12 lines are headers to be skipped nums = line.split(",") month = -1 for loc in nums: month += 1 if month==0: year = float(loc) continue if month==12 or not loc: break c.append(float(loc)) inc_c = [] # percent increase over the amount of the first year's value for i in range(len(c)): inc_c.append(100.*((c[i]/c[0])-1)) import matplotlib.pyplot as plt plt.plot(years, inc_b, c='purple', linewidth=3.0, label="Textbooks") plt.plot(years, inc_c, c='orange', linewidth=3.0, label="CPI") plt.xlabel("Year") five_year_mark_locs = list(range(1980, ending_year+1, 5)) plt.xticks(five_year_mark_locs) plt.xlim([1980, int(max(years)+1)]) plt.yticks([0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) plt.ylim([0, 1000]) plt.ylabel("% Increase Since 1980") plt.legend(loc='upper left') plt.title("Increase in textbook costs and CPI since 1980\n") ax = plt.gca() ax.set_aspect(.02) ax.spines['right'].set_visible(False) ax.spines['left'].set_visible(False) ax.spines['top'].set_visible(False) ax.spines['bottom'].set_visible(False) ytl = ['0%', '100%', '200%', '300%', '400%', '500%', '600%', '700%', '800%', '900%', '1,000%'] ax.set_yticklabels(ytl) plt.grid(which='major', axis='y', color='grey') plt.show(block=False) n = len(c) # how many years of data r = n-1 # index of latest year (last in the list) m=[] # relative increase of book price, adjusted for CPI change (inflation) for i in range(n): m.append((b[r]*c[i])/(b[i]*c[r])) years_backwards = [ending_year-x for x in years] plt.figure() from matplotlib import rc from matplotlib.font_manager import FontProperties rc('text', usetex=True) plt.plot(years_backwards, m, c='red', linewidth=3.0) font = FontProperties() font.set_size('x-large') plt.xlabel("Year in the past", fontproperties=font) five_year_mark_locs.reverse() five_year_mark_backwards = [str(x) for x in five_year_mark_locs] plt.xticks([ending_year-x for x in five_year_mark_locs]) plt.xlim([-int(1-min(years_backwards)), ending_year-1980]) plt.yticks([.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5]) plt.ylim([.5, 3.5]) plt.ylabel("Multiplier from actual to\nhypothetical book cost", fontproperties=font) plt.title("How much more textbooks would have had to cost in some past year,\nas a multiple of their actual cost that year, for their cost to have become\nwhat it is now, if their cost had been following basic inflation from\nthat year to now, rather than the actual (faster) increase", fontproperties=font, y=1.1) ax = plt.gca() ax.legend().set_visible(False) ax.set_aspect(9) ytl = ['.5', '1.0', '1.5', '2.0', '2.5', '3.0', '3.5'] ax.set_yticklabels(ytl, fontproperties=font) ax.set_xticklabels(five_year_mark_backwards, fontproperties=font) ax.spines['left'].set_visible(False) plt.grid(which='major', axis='x', color='grey') plt.grid(which='major', axis='y', color='grey') plt.show(block=False) plt.figure() from matplotlib import rc from matplotlib.font_manager import FontProperties rc('text', usetex=True) plt.plot(years_backwards, m, c='red', linewidth=3.0) font = FontProperties() font.set_size('x-large') plt.xlabel("Year you were in school", fontproperties=font) plt.xticks([ending_year-x for x in five_year_mark_locs]) plt.xlim([-int(1-min(years_backwards)), ending_year-1980]) plt.yticks([.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5]) plt.ylim([.5, 3.5]) plt.ylabel("Textbook pain multiplier", fontproperties=font) plt.title("Inflation-adjusted "+r"{\bf textbook pain multiplier}"+" from\nyour past experience of textbook costs to students'\nexperience today [where \"today\"=\""+last_month_name+", "+str(ending_year)+"\"]", fontproperties=font, y=1.1) ax = plt.gca() ax.legend().set_visible(False) ax.set_aspect(8) ax.set_yticklabels(ytl, fontproperties=font) xtl = ['2015', '2010', '2005', '2000', '1995', '1990', '1985', '1980'] ax.set_xticklabels(five_year_mark_backwards, fontproperties=font) ax.spines['left'].set_visible(False) plt.grid(which='major', axis='x', color='grey') plt.grid(which='major', axis='y', color='grey') plt.show(block=False)