from pandas import * from __future__ import division pandas.set_option('display.height', 500) pandas.set_option('display.max_rows', 500) pandas.set_option('display.max_columns', 500) pandas.set_option('display.width', 500) pandas.set_option('display.mpl_style', False) xls1 = ExcelFile('davies_1906_data.xlsx') population = xls1.parse('nbrhd_population') xls2 = ExcelFile('davies_1906_data.xlsx') employment = xls2.parse('nbrhd_employment', parse_dates=[0]) population figsize(12,10) fig, ax = subplots() x_loc = np.arange(13) num_items = 3.0 margin = 0.1 width = (1.-2.*margin)/num_items bar(x_loc, population['1900'], width, color='#A52A2A', label='1900') bar(x_loc+width, population['1910'], width, color='#C97F7F', label='1910') bar(x_loc+width*2.0, population['1920'], width, color='#E4BFBF', label='1920') ax.tick_params(axis='y', labelsize=15) ax.set_ylabel('San Francisco Population', fontsize=20) ax.set_xticks(x_loc+width) ax.set_xticklabels( ('South of Market', 'Mission District', 'Potrero Hill', 'Outer Mission', 'Pacific Heights', 'North Beach', 'Chinatown', 'Downtown', 'Panhandle Area', 'Sunset', 'Richmond', 'Military', 'All neighborhoods'), fontsize=20) for label in ax.get_xticklabels(): label.set_horizontalalignment('right') labels = ax.get_xticklabels() for label in labels: label.set_rotation(30) ax.legend(loc='upper left', fontsize=30) xlim(0,13) population['1900-1910 Change'] = 100.0*((population['1910'] - population['1900'])/ population['1900']) population['1910-1920 Change'] = 100.0*((population['1920'] - population['1910'])/ population['1910']) population figsize(12,10) fig, ax = subplots() x_loc = np.arange(13) num_items = 3.0 margin = 0.1 width = (1.-2.*margin)/num_items bar(x_loc, population['1900-1910 Change'], width, color='#333399', label='1900 to 1910') bar(x_loc+width, population['1910-1920 Change'], width, color='#9999CC', label='1910 to 1920') ax.set_ylabel('San Francisco Population Change (%)') ax.set_xticks(x_loc+width) ax.set_xticklabels( ('South of Market', 'Mission District', 'Potrero Hill', 'Outer Mission', 'Western Addition-Pacific Heights', 'North Beach', 'Chinatown', 'Downtown', 'Panhandle Area', 'Sunset', 'Richmond', 'Military', 'All neighborhoods')) for label in ax.get_xticklabels(): label.set_horizontalalignment('right') labels = ax.get_xticklabels() for label in labels: label.set_rotation(30) ax.legend() xlim(0,13) employment_by_year = employment.set_index(['Year','Neighborhood']) employment_by_year employment_by_year.ix['1900-01-01'] figsize(12,10) fig, ax = subplots() x_loc = np.arange(13) width = 0.35 num_items = 3.0 margin = 0.1 width = (1.-2.*margin)/num_items #1900 not_working1900=employment_by_year.ix['1900-01-01']['Not working'] working_class1900=employment_by_year.ix['1900-01-01']['Working class'] professional1900=employment_by_year.ix['1900-01-01']['Professional'] bar(x_loc, not_working1900, width, color='#252513') bar(x_loc, working_class1900, width, color='#949470', bottom=not_working1900) bar(x_loc, professional1900, width, color='#C2C2AD', bottom=not_working1900+working_class1900) # 1910 not_working1910=employment_by_year.ix['1910-01-01']['Not working'] working_class1910=employment_by_year.ix['1910-01-01']['Working class'] professional1910=employment_by_year.ix['1910-01-01']['Professional'] bar(x_loc+width, not_working1910, width, color='#252513') bar(x_loc+width, working_class1910, width, color='#949470', bottom=not_working1910) bar(x_loc+width, professional1910, width, color='#C2C2AD', bottom=not_working1910+working_class1910) # 1920 not_working1920=employment_by_year.ix['1920-01-01']['Not working'] working_class1920=employment_by_year.ix['1920-01-01']['Working class'] professional1920=employment_by_year.ix['1920-01-01']['Professional'] bar1 = bar(x_loc+2*width, not_working1920, width, color='#252513') bar2 = bar(x_loc+2*width, working_class1920, width, color='#949470', bottom=not_working1920) bar3 = bar(x_loc+2*width, professional1920, width, color='#C2C2AD', bottom=not_working1920+working_class1920) ylim(0,100) xlim(0,13) ax.tick_params(axis='y', labelsize=15) ax.set_ylabel('San Francisco Employment (%)', fontsize=20) ax.set_xticks(x_loc+width) ax.set_xticklabels( ('South of Market', 'Mission District', 'Potrero Hill', 'Outer Mission', 'Pacific Heights', 'North Beach', 'Chinatown', 'Downtown', 'Panhandle Area', 'Sunset', 'Richmond', 'Military', 'All neighborhoods'), fontsize=20) for label in ax.get_xticklabels(): label.set_horizontalalignment('right') labels = ax.get_xticklabels() for label in labels: label.set_rotation(30) ax.legend( (bar3[0], bar2[0], bar1[0]), ('Professional', 'Working class', 'Not working'), loc='lower left', fontsize=25) figsize(12,10) fig, ax = subplots() working_class_1900_1910 = 100.0*((working_class1910 - working_class1900) / working_class1900) scatter1 = scatter(population['1900-1910 Change'], working_class_1900_1910, color='k', marker='o', s=40, label='1900 to 1910') working_class_1910_1920 = 100.0*((working_class1920 - working_class1910) / working_class1910) scatter2 = scatter(population['1910-1920 Change'], working_class_1910_1920, s=40, label='1910 to 1920') ax.set_ylabel('Working Class Population Change (%)') ax.set_xlabel('Total Population Change (%)') ax.legend(loc='upper right')