python - Having trouble viewing more than one graph in the Spyder iPython console window -


i new coding in spyder 3 (with python 3.5 on windows7 laptop) & therefore having issue plotting graphs. reason when run code below, able view 1 graph. i've switched 2 graphs around , second 1 one shown in ipython console. think you'll find relevant code in last 12 lines. console output included after program. have no problem of rest of output. aspect of getting 1 graph... thanks!

import pandas import numpy import seaborn import matplotlib.pyplot plt  data = pandas.read_csv('addhealth_pds.csv', low_memory=false)  data["h1su1"]=data["h1su1"].convert_objects(convert_numeric=true) data["h1hr12"]=data["h1hr12"].convert_objects(convert_numeric=true) data["h1hr13"]=data["h1hr13"].convert_objects(convert_numeric=true) #theseven variables missing data changed "nan" elements,  #keeps them out of analysis. data["h1su1"]=data["h1su1"].replace(6,numpy.nan) data["h1su1"]=data["h1su1"].replace(8,numpy.nan) data["h1su1"]=data["h1su1"].replace(9,numpy.nan) data["h1hr12"]=data["h1hr12"].replace(96,numpy.nan) data["h1hr12"]=data["h1hr12"].replace(98,numpy.nan) data["h1hr13"]=data["h1hr13"].replace(96,numpy.nan) data["h1hr13"]=data["h1hr13"].replace(98,numpy.nan) #c1-3 , p1-3 show counts , percentages of respondents #answering 'noone'when asked "who in home acts  #mother (h1hr12) you?" same question asked of fathers #in section h1hr13. "noone" response denoted 0 print("counts h1hr12-who in household acts in place of mother you?, noone=0") c1 = data["h1hr12"].value_counts(sort=false)  print (c1) print("percentages h1hr12-who in household acts in place of mother you?, noone=0") p1 = data["h1hr12"].value_counts(sort=false, normalize= true)  print(p1) print("counts h1hr13-who in household acts in place of father you?, noone=0") c2 = data["h1hr13"].value_counts(sort=false)  print (c2) print("percentages h1hr13-who in household acts in place of father you?, noone=0") p2 = data["h1hr13"].value_counts(sort=false, normalize= true)  #next can see counts , percentages (c3 & p3)of respondents  #who answered yes question: #"have thought of suicide in past 12 months?" #a "yes" answer denoted "1" print("counts h1su1-have thought of suicide in past 12 months?, yes=1") c3 = data["h1su1"].value_counts(sort=false)  print (c3) print("percentagesfor h1su1-have thought of suicide in past 12 months?, yes=1") p3 = data["h1su1"].value_counts(sort=false, normalize= true) print (p3) #the subset of respondents have answered "yes" having non resident  #parent created, combine section h1hr12 , h1hr13  #subset "sub1" , copy "sub2". then, ask counts , #percentages of subset answered "yes" #thinking of suicide in previous 12 months. sub1=data[(data['h1hr13']==0) | (data['h1hr12']==0)] sub2 = sub1.copy() print("counts:(1 = yes response) non-resident parent & contemplated suicide") c4=sub2["h1su1"].value_counts(sort=false) print (c4) print("percentages:(1 = yes response) non-resident parent & contemplated suicide") p4=sub2["h1su1"].value_counts(sort=false, normalize=true) print (p4)  #the subset of respondents did not "yes" having non resident   #parent created, again combine section h1hr12 , h1hr13  #a subset.this time name dataframe "sub3" , copy "sub4" #then, ask counts , percentages of second subset  #did not answer "yes" #thinking of suicide in previous 12 months. sub3=data[(data['h1hr13']!=0) | (data['h1hr12']!=0)] sub4 = sub3.copy() print("counts: (1 = yes response) resident parent & contemplated suicide") c5=sub4["h1su1"].value_counts(sort=false) print (c5) print("percentages (1 = yes response) resident parent & contemplated   suicide") p5=sub4["h1su1"].value_counts(sort=false, normalize=true) print (p5) #code added create univariate graph our first variable sub2['h1su1'] = sub2['h1su1'].astype('category') seaborn.countplot(x='h1su1', data=sub2) plt.xlabel('27 of 186 (12.67%)') plt.title('respondents @ least 1 non-resident parent answered "yes" considering suicide in previous 12 months') #here code added univariate graph of second variable sub4['h1su1'] = sub4['h1su1'].astype('category') seaborn.countplot(x='h1su1', data=sub4) plt.xlabel('807 of 5524 (12.74%)') plt.title('respondents no non-resident parents (green) answered "yes" considering suicide in previous 12 months')                   output  counts h1hr12-who in household acts in place of mother you?, noone=0 97.0    6139 1.0      177 0.0      111 3.0       13 2.0       43 4.0        5 5.0        2 6.0        1 8.0        1 name: h1hr12, dtype: int64 percentages h1hr12-who in household acts in place of mother you?, noone=0 97.0    0.945625 1.0     0.027264 0.0     0.017098 3.0     0.002002 2.0     0.006624 4.0     0.000770 5.0     0.000308 6.0     0.000154 8.0     0.000154 name: h1hr12, dtype: float64 counts h1hr13-who in household acts in place of father you?, noone=0 97.0    6139 3.0       12 1.0       56 0.0      209 4.0        5 2.0       65 5.0        4 6.0        2 name: h1hr13, dtype: int64 percentages h1hr13-who in household acts in place of father you?, noone=0 counts h1su1-have thought of suicide in past 12 months?, yes=1 0.0    5614 1.0     821 name: h1su1, dtype: int64 percentagesfor h1su1-have thought of suicide in past 12 months?, yes=1 0.0    0.872416 1.0    0.127584 name: h1su1, dtype: float64 counts:(1 = yes response) non-resident parent & contemplated suicide 0.0    186 1.0     27 name: h1su1, dtype: int64 percentages:(1 = yes response) non-resident parent & contemplated suicide 0.0    0.873239 1.0    0.126761 name: h1su1, dtype: float64 counts: (1 = yes response) resident parent & contemplated suicide 0.0    5524 1.0     807 name: h1su1, dtype: int64 percentages (1 = yes response) resident parent & contemplated suicide 0.0    0.872532 1.0    0.127468 name: h1su1, dtype: float64 out[4]: <matplotlib.text.text @ 0x731a850> 

[.. mentioned, in spyder console above code followed second graph-which i've included link to...]


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -