@ -40,9 +40,14 @@ if do_univariate_kde:
@@ -40,9 +40,14 @@ if do_univariate_kde:
# Mongo lookup
cbsa = mt . CBSACode ( city ) [ 0 ]
pre_search = metaprops . find_one ( { ' geoid ' : cbsa } )
mongo_search = props . find ( { ' metroid ' : cbsa } )
mongo_search = props . find ( { ' $and ' : [
{ ' metroid ' : cbsa } ,
{ ' geoid ' : { ' $nin ' : [ cbsa ] } }
]
} )
if ' B17001 ' not in pre_search [ ' tables ' ] :
print " Error: could not find table B17001 for city " , city , " in db. "
@ -52,9 +57,14 @@ if do_univariate_kde:
@@ -52,9 +57,14 @@ if do_univariate_kde:
print " Error: could not find city " , city , " in db. "
continue
df = pd . DataFrame ( [ ] )
z = list ( mongo_search )
df = df . append ( z )
srch = list ( mongo_search )
for i , r in enumerate ( srch ) :
if cbsa in r [ ' geoid ' ] :
del srch [ i ]
break
df = df . append ( srch )
df = Table17001 ( df )
@ -63,23 +73,19 @@ if do_univariate_kde:
@@ -63,23 +73,19 @@ if do_univariate_kde:
# Percent of people in poverty
# overall, and by gender
xlim = 0.50
ylim = 5
f , ( ax1 , ax2 ) = plt . subplots ( 2 , 1 , sharex = True , figsize = ( 8 , 8 ) )
ax1 . set_title ( cities [ 0 ] )
#ax1.set_title(cities[0])
sns . kdeplot ( df [ ' P_Pct ' ] , shade = True , color = c3 , ax = ax1 )
sns . kdeplot ( df [ ' M_P_PctM ' ] , shade = True , color = c2 , ax = ax2 )
sns . kdeplot ( df [ ' F_P_PctF ' ] , shade = True , color = c1 , ax = ax2 ) ;
ax1 . set_xlim ( [ 0 , xlim ] )
ax2 . set_xlim ( [ 0 , xlim ] )
ax1 . set_xlim ( [ 0 , 1 ] )
ax2 . set_xlim ( [ 0 , 1 ] )
#
#ax1.set_ylim([0,ylim])
#ax2.set_ylim([0,ylim])
ax1 . set_ylim ( [ 0 , ylim ] )
ax2 . set_ylim ( [ 0 , ylim ] )
f . savefig ( " onecity_univariate_ " + city + " _1.jpg " )
#f.savefig("onecity_univariate_"+city+"_1.jpg")
@ -93,43 +99,43 @@ if do_univariate_kde:
@@ -93,43 +99,43 @@ if do_univariate_kde:
ylim = 5
f , ( ax1 , ax2 ) = plt . subplots ( 2 , 1 , sharex = True , figsize = ( 8 , 8 ) )
ax1 . set_title ( cities [ 0 ] + " " + cities [ 1 ] + " Pre-Adolesc " )
#ax1.set_title(cities[0] + " " + cities[1] + "Pre-Adolesc" )
sns . kdeplot ( df [ ' PAP_Pct ' ] , shade = True , color = c3 , ax = ax1 )
sns . kdeplot ( df2 [ ' PAP_Pct ' ] , shade = True , color = c2 , ax = ax1 )
#sns.kdeplot(df2['PAP_Pct'], shade=True, color=c2, ax=ax1 )
sns . kdeplot ( df [ ' PAM_P_PctM ' ] , shade = True , color = c2 , ax = ax2 )
sns . kdeplot ( df [ ' PAF_P_PctF ' ] , shade = True , color = c1 , ax = ax2 ) ;
ax1 . set_xlim ( [ 0 , xlim ] )
ax2 . set_xlim ( [ 0 , xlim ] )
ax1 . set_xlim ( [ 0 , 1 ] )
ax2 . set_xlim ( [ 0 , 1 ] )
#
#ax1.set_ylim([0,ylim])
#ax2.set_ylim([0,ylim])
ax1 . set_ylim ( [ 0 , ylim ] )
ax2 . set_ylim ( [ 0 , ylim ] )
f . savefig ( " onecity_univariate_ " + city + " _2.jpg " )
#f.savefig("onecity_univariate_"+city+"_2.jpg")
#######################
# Plot:
# Juvenile poverty levels
# (overall and by gender)
### ### ####################
### # Plot:
### # Juvenile poverty levels
### # (overall and by gender)
f , ( ax1 , ax2 ) = plt . subplots ( 2 , 1 , sharex = True , figsize = ( 8 , 8 ) )
ax1 . set_title ( cities [ 0 ] + " " + cities [ 1 ] + " Juveniles " )
sns . kdeplot ( df [ ' JuvP_Pct ' ] , shade = True , color = c3 , ax = ax1 )
sns . kdeplot ( df2 [ ' JuvP_Pct ' ] , shade = True , color = c2 , ax = ax1 )
sns . kdeplot ( df [ ' JuvM_P_PctM ' ] , shade = True , color = c2 , ax = ax2 )
sns . kdeplot ( df [ ' JuvF_P_PctF ' ] , shade = True , color = c1 , ax = ax2 ) ;
ax1 . set_xlim ( [ 0 , xlim ] )
ax2 . set_xlim ( [ 0 , xlim ] )
ax1 . set_ylim ( [ 0 , ylim ] )
ax2 . set_ylim ( [ 0 , ylim ] )
f . savefig ( " onecity_univariate_ " + city + " _3.jpg " )
### f, (ax1, ax2) = plt.subplots(2, 1, sharex=True, figsize=(8, 8) )
### #ax1.set_title(cities[0] + " " + cities[1] + "Juveniles" )
### sns.kdeplot( df['JuvP_Pct'], shade=True, color=c3, ax=ax1 )
### #sns.kdeplot(df2['JuvP_Pct'], shade=True, color=c2, ax=ax1 )
### sns.kdeplot( df['JuvM_P_PctM'], shade=True, color=c2, ax=ax2 )
### sns.kdeplot( df['JuvF_P_PctF'], shade=True, color=c1, ax=ax2) ;
###
### ax1.set_xlim([0,1] )
### ax2.set_xlim([0,1] )
### #
### #ax1.set_ylim([0,ylim] )
### #ax2.set_ylim([0,ylim] )
###
### #f.savefig("onecity_univariate_"+city+"_3.jpg" )
@ -139,18 +145,20 @@ if do_univariate_kde:
@@ -139,18 +145,20 @@ if do_univariate_kde:
# (overall and by gender)
f , ( ax1 , ax2 ) = plt . subplots ( 2 , 1 , sharex = True , figsize = ( 8 , 8 ) )
ax1 . set_title ( cities [ 0 ] + " " + cities [ 1 ] + " Seniors " )
#ax1.set_title(cities[0] + " " + cities[1] + "Seniors" )
sns . kdeplot ( df [ ' SrP_Pct ' ] , shade = True , color = c3 , ax = ax1 )
sns . kdeplot ( df2 [ ' SrP_Pct ' ] , shade = True , color = c2 , ax = ax1 )
#sns.kdeplot(df2['SrP_Pct'], shade=True, color=c2, ax=ax1 )
sns . kdeplot ( df [ ' SrM_P_PctM ' ] , shade = True , color = c2 , ax = ax2 )
sns . kdeplot ( df [ ' SrF_P_PctF ' ] , shade = True , color = c1 , ax = ax2 ) ;
ax1 . set_xlim ( [ 0 , 1 ] )
ax2 . set_xlim ( [ 0 , 1 ] )
#
#ax1.set_ylim([0,ylim])
#ax2.set_ylim([0,ylim])
ax1 . set_xlim ( [ 0 , xlim ] )
ax2 . set_xlim ( [ 0 , xlim ] )
ax1 . set_ylim ( [ 0 , ylim ] )
ax2 . set_ylim ( [ 0 , ylim ] )
f . savefig ( cities [ 0 ] + " _g2_3.jpg " )
#f.savefig(cities[0]+"_g2_3.jpg")
plt . show ( )
plt . draw ( )