In [1]:
# -*- coding: UTF-8 -*-
# Render our plots inline
%matplotlib inline
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import seaborn
import shutil
pd.set_option('display.mpl_style', 'default') # Make the graphs a bit prettier, overridden by seaborn
pd.set_option('display.max_columns', None) # Display all the columns
plt.rcParams['font.family'] = 'sans-serif' # Sans Serif fonts for all the graphs
# Reference for color palettes: http://web.stanford.edu/~mwaskom/software/seaborn/tutorial/color_palettes.html
# Change the font
matplotlib.rcParams.update({'font.family': 'Source Sans Pro'})
In [2]:
# Load csv file first
data = pd.read_csv("data/results-makers-40.csv", encoding="utf-8")
In [3]:
# Check data
#data[0:4] # Equals to data.head()
In [4]:
%%capture output
# Save the output as a variable that can be saved to a file
# Get the distribution of way of living
living = data["Q011"].value_counts(dropna=False)
print "Data:"
print living
print ""
print "Data %:"
print data["Q011"].value_counts(normalize=True,dropna=False) * 100
In [5]:
# Save+show the output to a text file
%save Q011-MakerComeVivi01.py str(output)
shutil.move("Q011-MakerComeVivi01.py", "text/Q011-MakerComeVivi01.txt")
In [6]:
# Plot the data
plt.figure(figsize=(8,6))
plt.xlabel(u'Modalitá', fontsize=16)
plt.ylabel('Persone', fontsize=16)
plt.title("Come vivi?", fontsize=18, y=1.02)
my_colors = seaborn.color_palette("husl", len(living)) # Set color palette
living.plot(kind="bar",color=my_colors)
plt.savefig("svg/Q011-MakerComeVivi01.svg")
plt.savefig("png/Q011-MakerComeVivi01.png")
plt.savefig("pdf/Q011-MakerComeVivi01.pdf")
In [7]:
%%capture output
# Save the output as a variable that can be saved to a file
# Get "other" data
living_other = data["Q011[other]"].str.lower().value_counts()
print "Data:"
print living_other
print ""
print "Data %:"
print data["Q011[other]"].str.lower().value_counts(normalize=True) * 100
In [8]:
# Save+show the output to a text file
%save Q011-MakerProfilo.py str(output)
shutil.move("Q011-MakerProfilo.py", "text/Q011-MakerProfilo.txt")
In [9]:
# Plot bar
plt.figure(figsize=(8,6))
plt.title('Come vivi? Altro', fontsize=18, y=1.02)
plt.xticks(range(len(living_other.index)),living_other.index,rotation=90)
plt.xlabel(u'Modalitá', fontsize=16)
plt.ylabel('Persone', fontsize=16)
ind = np.arange(len(living_other)) # the x locations for the groups
width = 0.35 # the width of the bars
my_colors = seaborn.color_palette("husl", len(living_other)) # Set color palette
rect1 = plt.bar(ind,living_other,width,color=my_colors,align='center')
plt.savefig("svg/Q011-MakerComeVivi02.svg")
plt.savefig("png/Q011-MakerComeVivi02.png")
plt.savefig("pdf/Q011-MakerComeVivi02.pdf")
In [10]:
living["Da solo con figli"] = 4
living["Con i genitori"] += 1
living["Altro"] -= 5
In [11]:
%%capture output
# Save the output as a variable that can be saved to a file
print "Data:"
print living
print ""
print "Data %:"
print living/living.sum()
In [12]:
# Save+show the output to a text file
%save Q011-MakerProfilo01.py str(output)
shutil.move("Q011-MakerProfilo01.py", "text/Q011-MakerProfilo01.txt")
In [13]:
# Plot the data
plt.figure(figsize=(8,6))
plt.xlabel(u'Modalitá', fontsize=16)
plt.ylabel('Persone', fontsize=16)
plt.title("Come vivi?", fontsize=18, y=1.02)
my_colors = seaborn.color_palette("husl", len(living)) # Set color palette
living.plot(kind="bar",color=my_colors)
plt.savefig("svg/Q011-MakerComeVivi03.svg")
plt.savefig("png/Q011-MakerComeVivi03.png")
plt.savefig("pdf/Q011-MakerComeVivi03.pdf")