Justetc Social Services (non-profit)Jan 31 · 4 min read
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inlinefrom __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgetshealth_status = pd.read_excel('../data/health-status.xls')
health_status.head()
health_status.set_index(['Indicator'])
#health_status.loc[health_status['Cancer Mortality (F)']]
#health_status.index.unique()
indicators = pd.Index(health_status['Indicator']).unique()
years = health_status['Data year'].unique()
indicators[0], years[0]('Cancer Mortality (F)', '2013')cancer_mortality_2013 = health_status.loc[ (health_status['Indicator'] == indicators[0]) & (health_status['Data year'] == years[0]) ]
cancer_mortality = health_status.loc[ (health_status['Indicator'] == indicators[0]) & (health_status['Data year'] != 2012) ]
cancer_mortality
plt.rcParams['figure.figsize'] = [15, 9]
#plt.scatter(cancer_mortality['Data year'], cancer_mortality['Value']) #, s=cancer_mortality['Value']*10)
for aYear in years:
data = health_status.loc[ (health_status['Indicator'] == indicators[0]) & (health_status['Data year'] == aYear) ]
plt.scatter(data['Data year'], data['Region'], s=cancer_mortality['Value']*10 )
plt.show()
years = [ int(aYear) for aYear in years if (aYear != 'Not applicable') and len( str(aYear).split(' ')) <= 1 ]
years = sorted(years)
years[2012, 2013, 2013, 2014, 2014, 2015, 2015]plt.rcParams['figure.figsize'] = [8, 15]
from matplotlib import pyplot as plt
f = plt.figure()
ax = f.gca()
f.show()
#years = [2012, 2013, 2014, 2015, 2016, 2017, 2018]
for aYear in years:
#print(aYear)
if (aYear=='Not applicable'):
continue
#ax = fig.add_subplot(111)
data = health_status.loc[ (health_status['Indicator'] == indicators[0]) & (health_status['Data year'] == aYear) ]
ax.scatter(data['Data year'], data['Region'], s=cancer_mortality['Value']*20 )
#line1.set_ydata(data['Region'])
f.canvas.draw()
#plt.show()
#plt.pause(1)
#ax.clear()
#fig.canvas.draw()
#plt.legend()C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\figure.py:445: UserWarning: Matplotlib is currently using module://ipykernel.pylab.backend_inline, which is a non-GUI backend, so cannot show the figure.
% get_backend())
plt.rcParams['figure.figsize'] = [5, 5]
plt.ion()
fig = plt.figure()
ax = fig.add_subplot(111)
#line1, = ax.plot(cancer_mortality_2013['Data year'], cancer_mortality_2013['Region'], 'b')
#pl = ax.scatter(cancer_mortality_2013['Data year'], cancer_mortality_2013['Region'], s=cancer_mortality_2013['Value']*30 )
fig = plt.figure()
ax = fig.add_subplot(111)
years = [2012, 2013, 2014, 2015]
for aYear in years:
print(aYear)
ax = fig.add_subplot(111)
data = health_status.loc[ (health_status['Indicator'] == indicators[0]) & (health_status['Data year'] == aYear) ]
ax.scatter(data['Data year'], data['Region'], s=cancer_mortality['Value']*10 )
#line1.set_ydata(data['Region'])
plt.show()
plt.pause(0.0001)
ax.clear()
#fig.canvas.draw()
#for phase in np.linspace(0, 10*np.pi, 100):
#line1.set_ydata(np.sin(0.5 * x + phase))
#fig.canvas.draw()2012
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\figure.py:98: MatplotlibDeprecationWarning:
Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
"Adding an axes using the same arguments as a previous axes "
2013
2014
2015plt.rcParams['figure.figsize'] = [15, 9]
plt.scatter(cancer_mortality_2013['Data year'], cancer_mortality_2013['Region'], s=cancer_mortality_2013['Value']*30 )
plt.show()
plt.rcParams['figure.figsize'] = [15, 9]
plt.scatter(cancer_mortality_2013['Region'], cancer_mortality_2013['Value'], s=cancer_mortality_2013['Value']*30 )
plt.show()
plt.rcParams['figure.figsize'] = [100, 50]
from matplotlib import pyplot as plt
f = plt.figure()
ax = f.gca()
f.show()
#years = [2012, 2013, 2014, 2015, 2016, 2017, 2018]
for aYear in years:
#print(aYear)
if (aYear=='Not applicable'):
continue
#ax = fig.add_subplot(111)
data = health_status.loc[ (health_status['Indicator'] == indicators[0]) & (health_status['Data year'] == aYear) ]
#ax.scatter(data['Data year'], data['Region'], s=cancer_mortality['Value']*20 )
ax.scatter(data['Region'], data['Value'], s=cancer_mortality['Value']*100 )
#line1.set_ydata(data['Region'])
f.canvas.draw()
#plt.show()
#plt.pause(1)
#ax.clear()
#fig.canvas.draw()
#plt.legend()
def f(x):
return x
w = interact(f, x=indicators);
interact(f, x=years);interactive(children=(Dropdown(description='x', options=('Cancer Mortality (F)', 'Cancer Mortality (M)', 'Hear…
interactive(children=(Dropdown(description='x', options=(2012, 2013, 2014, 2015), value=2012), Output()), _dom…w = interactive(f, x=indicators);type(w)ipywidgets.widgets.interaction.interactivew.children(Dropdown(description='x', options=('Cancer Mortality (F)', 'Cancer Mortality (M)', 'Heart Disease Mortality', 'Infant Mortality', 'Life Expectancy at Birth (F)', 'Life Expectancy at Birth (M)', 'Perceived Health Status', 'Stroke Mortality', 'Suicide (F)', 'Suicide (M)', 'Transport Accident Mortality (F)', 'Transport Accident Mortality (M)'), value='Cancer Mortality (F)'),
Output())display(w)interactive(children=(Dropdown(description='x', options=('Cancer Mortality (F)', 'Cancer Mortality (M)', 'Hear…w.result'Perceived Health Status'