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 time of working on making
time = data["Q017"].value_counts(dropna=False)
print "Data:"
print time
print ""
print "Data %:"
print data["Q017"].value_counts(normalize=True,dropna=False) * 100
In [5]:
# Save+show the output to a text file
%save Q017-MakerEsperienza01.py str(output)
shutil.move("Q017-MakerEsperienza01.py", "text/Q017-MakerEsperienza01.txt")
In [6]:
# Plot the data
plt.figure(figsize=(8,6))
plt.xlabel(u'Tempo', fontsize=16)
plt.ylabel('Persone', fontsize=16)
plt.title("Da quanto tempo ti occupi di making?", fontsize=18, y=1.02)
my_colors = seaborn.color_palette("husl", len(time)) # Set color palette
time.plot(kind="bar",color=my_colors)
plt.savefig("svg/Q017-MakerEsperienza01.svg")
plt.savefig("png/Q017-MakerEsperienza01.png")
plt.savefig("pdf/Q017-MakerEsperienza01.pdf")
In [7]:
%%capture output
# Save the output as a variable that can be saved to a file
# Order of the choices
time_order = ["Meno di 1 anno","Da 1 a 5 anni","Da 5 a 10 anni","Oltre 10 anni"]
time2 = time.reindex(time_order)
# Get the distribution of way of living, reindexed
print "Data:"
print time2
print ""
print "Data %:"
time2_normalized = data["Q017"].value_counts(normalize=True,dropna=False) * 100
print time2_normalized.reindex(time_order)
In [8]:
# Save+show the output to a text file
%save Q017-MakerEsperienza02.py str(Q017b)
shutil.move("Q017-MakerEsperienza02.py", "text/Q017-MakerEsperienza02.txt")
In [9]:
# Plot the data
plt.figure(figsize=(8,6))
plt.xlabel(u'Tempo', fontsize=16)
plt.ylabel('Persone', fontsize=16)
plt.title("Da quanto tempo ti occupi di making?", fontsize=18, y=1.02)
my_colors = seaborn.color_palette("husl", len(time2)) # Set color palette
time2.plot(kind="bar",title="Da quanto tempo ti occupi di making?",color=my_colors)
plt.savefig("svg/Q017-MakerEsperienza02.svg")
plt.savefig("png/Q017-MakerEsperienza02.png")
plt.savefig("pdf/Q017-MakerEsperienza02.pdf")
In [9]: