In [1]:
# Librerie
import os
import pandas as pd
import numpy as np
import folium
import matplotlib.pyplot as plt
plt.style.use('ggplot')
get_ipython().magic('pylab inline')
In [2]:
# Cartelle Input/Output
dir_df = os.path.join(os.path.abspath(''),'stg')
dir_out = os.path.join(os.path.abspath(''),'output')
In [3]:
df_g2_filename = r'df_g2.pkl'
df_g2_fullpath = os.path.join(dir_df, df_g2_filename)
df_g2 = pd.read_pickle(df_g2_fullpath)
In [6]:
df_g2.head(2)
Out[6]:
In [4]:
df_g2 = df_g2[df_g2['Territorio']!='Italia']
In [7]:
df_g2['Popolazione residente'] = df_g2['Popolazione residente']/100000
In [21]:
style.use('fivethirtyeight')
import matplotlib.ticker as mtick
# Report G2
tp = df_g2.plot(
x='Reddito pro capite',
y='Gradio di soddisfazione per la vita',
s=df_g2['Popolazione residente'],
kind='scatter',
xlim=(0,75000),
ylim=(0,10),
legend = False,
figsize = (6,4))
for i, txt in enumerate(df_g2.Territorio):
tp.annotate(txt, (df_g2['Reddito pro capite'].iat[i]*1.070,df_g2['Gradio di soddisfazione per la vita'].iat[i]))
tp.plot()
tp.tick_params(axis = 'both', which = 'major', labelsize = 10)
# Generate a bolded horizontal line at y = 0
tp.axhline(y = 0, color = 'black', linewidth = 4, alpha = 0.7)
tp.axvline(x = 500, color = 'black', linewidth = 0.8, alpha = 0.7)
# Remove the label of the x-axis
#tp.xaxis.label.set_visible(False)
#tp.yaxis.label.set_visible(False)
tp.set_ylabel('Gradio di soddisfazione per la vita (scala 1-10)',fontsize=8)
tp.set_xlabel('Reddito pro capite (euro)',fontsize=8)
fmt = '{x:,.0f}'
tick = mtick.StrMethodFormatter(fmt)
tp.xaxis.set_major_formatter(tick)
text = tp.text(x = -7000, y = -2,
s = 'www.ildatomancante.it Fonte: Istat',
fontsize = 10, color = '#f0f0f0', backgroundcolor = 'grey')
text.set_url('http://www.ildatomancante.it/opendata/popolazione/799/la-grande-fuga-salute-ricchezza-e-origini-della-disuguaglianza-in-italia/')
# Adding a title and a subtitle Reddito e aspettativa di vita
tp.text(x = 1000, y = 11.7, s = "Grado di soddsifazione per la vita in Italia",
fontsize = 14, weight = 'bold', alpha = .75)
tp.text(x = 1000, y = 10.5,
s = '''Relazione tra il grado di soddisfazine per la vita e il reddito pro capite \ndei cittadini italiani. Ultimi dai aggiornati al 2015.''',
fontsize = 10, alpha = .85)
fig_prj = tp.get_figure()
fig_prj.savefig(os.path.join(dir_out,'G2_Reddito_e_Soddisfazione.png'), format='png', dpi=300,bbox_inches='tight')
fig_prj.savefig(os.path.join(dir_out,'G2_Reddito_e_Soddisfazione.svg'), format='svg', dpi=300,bbox_inches='tight')
In [8]:
df_g2.to_csv(os.path.join(dir_out,r'G2_Preston.csv'),header=True, index=False)