Q012-Q013 - Quando è iniziata la progettazione del laboratorio? / Quando è stato inaugurato il laboratorio?


In [1]:
# -*- coding: UTF-8 -*-

# Render our plots inline
%matplotlib inline 

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
import matplotlib.lines as mlines
import numpy as np
import seaborn
import math
import datetime as dt

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'})

rcParams['figure.figsize'] = 10, 20

In [2]:
# Load csv file first
data = pd.read_csv("data/lab-survey.csv", encoding="utf-8")

In [3]:
history_columns = ['D1','D12','D13']
history = data[history_columns]

In [4]:
rows = []
for i in range(len(data.index)):
    rows.append(i)
history["Row"] = pd.Series(rows)


-c:4: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

In [5]:
#history

In [6]:
labs = list(history["D1"].values.tolist())

# Get min and max values, and extend the time range by 60 days
start1 = pd.to_datetime(history["D12"][history["D12"].notnull()].min())
dStart = start1.to_datetime()
dStart -= datetime.timedelta(days=60)

end1 = pd.to_datetime(history["D13"][history["D13"].notnull()].max())
dEnd = end1.to_datetime()
dEnd += datetime.timedelta(days=60)

In [7]:
# From http://stackoverflow.com/questions/7684475/plotting-labeled-intervals-in-matplotlib-gnuplot

from matplotlib.dates import DateFormatter, MinuteLocator, SecondLocator
import datetime as dt
from pylab import rcParams


# Timeline function
def timelines(y, xstart, xstop, color='b', style="-"):  
    plt.hlines(y, xstart, xstop, color, lw=3, linestyles=style)
    plt.vlines(xstart, y+0.3, y-0.3, color, lw=2)
    plt.vlines(xstop, y+0.3, y-0.3, color, lw=2)

# Plot all the timelines
for i in history.index:
    # Check if the lab is closing...
    if data["D3"][i] == "in chiusura":
        color = "y"
    else:
        color = "g"
    start = pd.to_datetime(history["D12"][i])
    end = pd.to_datetime(history["D13"][i])
    # Debut
    print history["D1"][i],start,end
    if type(history["D12"][i]) == float and math.isnan(history["D12"][i]):
        # There is no start, i.e. no design process, only inauguration
        start = end
        timelines(history["Row"][i], start, end, 'c', style="--")
        timelines(history["Row"][i], end, dEnd, color, style="-")
    elif type(history["D13"][i]) == float and math.isnan(history["D13"][i]):
        # There is no inauguration yet
        timelines(history["Row"][i], start, dEnd, 'c', style="--")
    else:
        timelines(history["Row"][i], start, end, 'c', style="--")
        timelines(history["Row"][i], end, dEnd, color, style="-")
    

#Setup the plot
ax = plt.gca()
ax.xaxis_date()
myFmt = DateFormatter('%Y-%m-%d')
ax.xaxis.set_major_formatter(myFmt)
ax.yaxis.set_ticks(range(len(labs)))
ax.yaxis.set_ticklabels(labs)
plt.xlim(dStart,dEnd)
plt.ylim(-1,len(labs)+3) # Give extra space for legend at the top and for the first value at the bottom
plt.xlabel('Periodo', fontsize=16)
plt.ylabel('Lab', fontsize=16)
plt.title('Periodo di sviluppo dei laboratori', fontsize=18, y=1.02)

# Setup legend
design_line = mlines.Line2D([], [], color='c', ls="--", lw=3,  label='Progettazione')
open_line = mlines.Line2D([], [], color='g', ls="-", lw=3,  label='Aperto')
closing_line = mlines.Line2D([], [], color='y', ls="-", lw=3,  label='Aperto ma in chiusura')
plt.legend(handles=[design_line,open_line,closing_line])

# Create, save, show the plot
plt.savefig("svg/Q012-13-PeriodoDiSviluppo.svg")
plt.savefig("png/Q012-13-PeriodoDiSviluppo.png")
plt.savefig("pdf/Q012-13-PeriodoDiSviluppo.pdf")
plt.show()


+LAB 2013-05-01 00:00:00 2013-11-16 00:00:00
Cenadistore 2014-05-05 00:00:00 2014-06-10 00:00:00
Creaticity FabLab 2013-09-01 00:00:00 2014-02-09 00:00:00
Crunchlab 2012-09-29 00:00:00 2014-04-02 00:00:00
cssm tecnos 2014-01-01 00:00:00 2014-07-06 00:00:00
FAB LAB CASCINA 2013-09-01 00:00:00 2014-03-29 00:00:00
Fab Lab FVG (provvisorio) 2014-03-22 00:00:00 NaT
Fab Lab Junior Bagnacavallo 2013-12-27 00:00:00 2014-03-26 00:00:00
fab lab Pavia - Geco Fab lab presso >Spazio Geco 2014-01-12 00:00:00 2014-10-12 00:00:00
Fab Lab Reggio Emilia 2012-03-01 00:00:00 2012-10-27 00:00:00
fab lab roma makers 2011-08-19 00:00:00 2014-10-01 00:00:00
Fab Lab terni 2013-03-11 00:00:00 2013-11-23 00:00:00
Fab Lab Treviso 2014-05-01 00:00:00 NaT
FaberLab Varese 2013-05-19 00:00:00 2014-03-21 00:00:00
FabLab Alessandria 2014-03-08 00:00:00 2014-03-08 00:00:00
FABLAB CALABRIA 2014-01-07 00:00:00 2014-01-13 00:00:00
Fablab Catania NaT 2014-05-08 00:00:00
FabLab Faenza 2013-11-01 00:00:00 2014-04-14 00:00:00
FabLab Firenze 2014-03-07 00:00:00 2012-09-07 00:00:00
Fablab Frosinone | Officine Giardino 2013-10-03 00:00:00 2014-01-10 00:00:00
FabLab Imperia 2013-11-15 00:00:00 2014-11-30 00:00:00
FabLab Ivrea 2013-09-30 00:00:00 2014-06-12 00:00:00
FabLab Mattei 2013-11-28 00:00:00 NaT
FabLab Messina 2013-01-01 00:00:00 2014-10-09 00:00:00
fablab milano 2013-05-13 00:00:00 2013-11-04 00:00:00
Fablab Palermo 2014-01-19 00:00:00 2014-07-19 00:00:00
Fablab Pesaro 2013-11-04 00:00:00 2014-12-01 00:00:00
Fablab Roma SPQwoRk 2013-10-01 00:00:00 2014-04-01 00:00:00
FabLab Romagna 2013-05-13 00:00:00 2014-12-12 00:00:00
FABLAB SARDEGNA RICERCHE 2013-08-08 00:00:00 2014-02-10 00:00:00
FabLab Settimo 2013-06-01 00:00:00 2014-04-18 00:00:00
FABLAB TORINO 2011-12-01 01:00:00 2012-02-17 00:00:00
FabLab udine 2014-03-22 00:00:00 NaT
Fablab Valdarno 2014-07-01 00:00:00 NaT
FabLab VdA 2013-12-01 00:00:00 2014-01-30 00:00:00
Fablab Venezia 2013-03-11 00:00:00 2014-02-18 00:00:00
FABLAB.NU 2014-02-21 00:00:00 2014-06-28 00:00:00
FabLabGenova 2013-02-03 00:00:00 NaT
FAMO COSE Roma Makerspace 2014-05-05 00:00:00 2014-09-13 00:00:00
HackLab Terni 2011-10-22 00:00:00 2012-09-11 00:00:00
ICTP Scientific FabLab (SciFabLab) 2014-05-17 00:00:00 2014-08-12 00:00:00
Labcake 2013-04-01 00:00:00 2013-10-25 00:00:00
Let's Make 2014-10-18 00:00:00 2014-02-08 00:00:00
LOFOIO 2014-11-07 00:00:00 2014-05-07 00:00:00
Made in MaGe 2011-01-01 00:00:00 2011-01-22 00:00:00
MakeInBo Fab Lab Bologna 2012-01-01 00:00:00 2014-02-07 00:00:00
MakeRN FabLab Rimini 2013-05-01 00:00:00 NaT
Miocugino - officina di gesta e ingegno 2013-01-22 00:00:00 2013-04-13 00:00:00
ON/OFF FABLAB PARMA 2014-01-01 00:00:00 2014-03-10 00:00:00
Open Wet Lab 2013-09-06 00:00:00 2014-02-06 00:00:00
opendot 2013-02-11 00:00:00 2014-09-25 00:00:00
OpenLAB 2014-03-01 00:00:00 2014-06-21 00:00:00
Phyrtual Innovation Gym 2013-06-15 00:00:00 2014-03-20 00:00:00
Prototype Factory 2014-10-18 00:00:00 2014-10-18 00:00:00
RaspiBO 2012-12-20 00:00:00 2013-02-07 00:00:00
Sibillini 3D Lab - FabLab Sibillini 2014-02-01 00:00:00 2014-05-30 00:00:00
Stardust* 2008-11-28 00:00:00 2015-01-01 00:00:00
Studio MP ( Fab Lab Sesto fiorentino ) 2011-05-02 00:00:00 2011-06-06 00:00:00
Syskrack Lab 2013-08-18 00:00:00 2014-01-25 00:00:00
Talentlab Civitas Vitae 2014-01-10 00:00:00 2013-09-22 00:00:00
TechLab 2013-01-01 00:00:00 2014-05-18 00:00:00
The Fablab: Make in Milano 2014-05-14 00:00:00 2014-07-14 00:00:00
TIS FabLab 2012-05-01 00:00:00 2014-03-29 00:00:00
Unterwelt 2011-11-01 00:00:00 2011-11-01 00:00:00
Valdambra FabLab 2014-07-11 00:00:00 NaT
Verona FabLab 2013-09-01 00:00:00 2014-05-25 00:00:00
We Do Fablab 2012-09-11 00:00:00 2013-05-14 00:00:00
WECANLAB 2011-06-05 00:00:00 2014-03-01 00:00:00
WeMake - Milan's Makerspace 2012-01-02 00:00:00 2014-06-11 00:00:00
YATTA! Fai da noi 2014-01-07 00:00:00 2014-04-08 00:00:00

In [8]:
years = [2008, 2009,2010,2011,2012,2013,2014,2015]
design_year = {}
for k in years:
    design_year[k] = 0
for i in history.index:
    design = pd.to_datetime(history["D12"][i])
    for k in years:
        if design.year == k:
            design_year[k] += 1

design_start = pd.Series(design_year)

In [9]:
# Plot the data
plt.figure(figsize=(16,6))
plt.xlabel(u'Anno', fontsize=16)
plt.ylabel('Lab', fontsize=16)
plt.title(u"Anno di inizio progettazione", fontsize=18, y=1.02)
my_colors = seaborn.color_palette("husl", len(design_start)) # Set color palette
design_start.plot(kind="bar",color=my_colors)
plt.savefig(u"svg/Q012-13-AnniProgettazione.svg")
plt.savefig(u"png/Q012-13-AnniProgettazione.png")
plt.savefig(u"pdf/Q012-13-AnniProgettazione.pdf")



In [10]:
years = [2008,2009,2010,2011,2012,2013,2014,2015]
opening_year = {}
for k in years:
    opening_year[k] = 0
for i in history.index:
    inauguration = pd.to_datetime(history["D13"][i])
    for k in years:
        if inauguration.year == k:
            opening_year[k] += 1

inauguration = pd.Series(opening_year)

In [11]:
# Plot the data
plt.figure(figsize=(16,6))
plt.xlabel(u'Anno', fontsize=16)
plt.ylabel('Lab', fontsize=16)
plt.title(u"Anno di apertura", fontsize=18, y=1.02)
my_colors = seaborn.color_palette("husl", len(inauguration)) # Set color palette
inauguration.plot(kind="bar",color=my_colors)
plt.savefig(u"svg/Q012-13-AnniApertura.svg")
plt.savefig(u"png/Q012-13-AnniApertura.png")
plt.savefig(u"pdf/Q012-13-AnniApertura.pdf")



In [11]: