In [13]:
# Python tools needed: jupyter, pandas, plotly, colorlover, 

import plotly.offline as pl
import pandas as pd
import colorlover as cl
import numpy as np
from plotly.graph_objs import *
pl.init_notebook_mode()



In [30]:
df = pd.DataFrame({
'Statistics' :     [None,None,None,   5,  35,  51,65,83,95,100,103,105,109,112],
'Programming' :    [15  ,  20,  22,  35,  50,  63,69,75,88, 93,92 , 94, 95,99],
'Business Intelligence' : [None,None,None,None,None,None,None, 5,20,43, 60, 71, 75, 82],
'Nerdiness': [68,70,75,80,82,87,85,90,88,89,87,90,92,95],
'Data Strategy' : [None,None,None,None,None,None,None, None,None,5, 18, 40,55, 68],
}, index=range(2005,2019))

df.head()


Out[30]:
Business Intelligence Data Strategy Nerdiness Programming Statistics
2005 NaN NaN 68 15 NaN
2006 NaN NaN 70 20 NaN
2007 NaN NaN 75 22 NaN
2008 NaN NaN 80 35 5
2009 NaN NaN 82 50 35

In [20]:
def myLine(topic):
    c = color_iterator.next()
    
    return [Scatter(
        x = df.index[df.index<=2016],
        y = df[topic][df.index<=2016],
        name=topic,
        mode='lines',
       line=Line(color=c)
    ), Scatter(
        x = df.index[df.index>=2016],
        y = df[topic][df.index>=2016],
        name=topic,
        mode='lines',
        line=Line(dash="dot", color=c)   
    )]

def shading(start, end, color='#d3d3d3') :
    
    
     return {
            'type': 'rect',
            # x-reference is assigned to the x-values
            'xref': 'x',
            # y-reference is assigned to the plot paper [0,1]
            'yref': 'paper',
            'x0': str(start),
            'y0': 0,
            'x1': str(end),
            'y1': 1.15,
            'fillcolor': color,
            'opacity': 0.2,
            'line': {
                'width': 0,
            }
        }
    
def anno1(topic):
    year = df.index[df[topic].notnull()][0]
    y = df[topic][year]
    return Annotation(
        text=topic,     # text is the y-coord
        showarrow=False, # annotation w/o arrows, default is True
        x=year,               # set x position
        xref='x',          # position text horizontally with x-coords
        xanchor='right',  # x position corresp. to center of text
        yref='y',            # set y position 
        yanchor='middle',       # position text vertically with y-coords
        y=y,                 # y position corresp. to top of text
        font=Font(family='Arial',
            color='#000',  # set font color
            size=11           #   and size   
        ),      
    )
def anno2(topic, start, end, color='#d3d3d3'):
  
    return Annotation(
        text=topic,     # text is the y-coord
        showarrow=False, # annotation w/o arrows, default is True
        x=(end+start)/2,               # set x position
        xref='x',          # position text horizontally with x-coords
        xanchor='center',  # x position corresp. to center of text
        yref='paper',            # set y position 
        yanchor='top',       # position text vertically with y-coords
        y=1.15,                 # y position corresp. to top of text
        font=Font(family='Arial',
            color='#4d4d4d',  # set font color
            size=13           #   and size   
        ),      
    )

In [31]:
color_iterator = iter(['rgb(228,26,28)',
 'rgb(55,126,184)',
 'rgb(77,175,74)',
 'rgb(255,127,0)',
 'rgb(255,255,51)'])

annos = Annotations([anno1(k) for k in df.columns] +[
                anno2('''<b>Ghent University</b> <br> Mathematics, MSc''', 2008, 2012, color='#d3d3d3'),
               anno2("<b>SAS Belgium</b> <br> Analytical consultant", 2012, 2015.5, color='#d30000'),
               anno2("<b>SAS Toronto</b> <br> Data Science <br> Specialist", 2015.5, 2018, color='#dddd00'),
               Annotation(
        text="<b>Jos Polfliet - experience*</b>",     # text is the y-coord
        showarrow=False, # annotation w/o arrows, default is True
        x=0,               # set x position
        xref='paper',          # position text horizontally with x-coords
        xanchor='left',  # x position corresp. to center of text
        yref='paper',            # set y position 
        yanchor='bottom',       # position text vertically with y-coords
        y=1.2,                 # y position corresp. to top of text
        font=Font(family='Arial',
            color='#4d4d4d',  # set font color
            size=16           #   and size   
        ),      
    )      ,
        Annotation(
        text="<i>* Self-assessed</i>",     # text is the y-coord
        showarrow=False, # annotation w/o arrows, default is True
        x=0,               # set x position
        xref='paper',          # position text horizontally with x-coords
        xanchor='left',  # x position corresp. to center of text
        yref='paper',            # set y position 
        yanchor='top',       # position text vertically with y-coords
        y=1.2,                 # y position corresp. to top of text
        font=Font(family='Arial',
            color='#4d4d4d',  # set font color
            size=11           #   and size   
        ),      
    )      
                    ] )
fig = Figure(
    data=Data( [l for k in df.columns for l in myLine(k) ]  ),
    layout=Layout(
        barmode='overlay',
        autosize=False,   # (!) turn off autosize 
        height=550,       # plot's height and
        width=850,  
        xaxis=XAxis(autotick=False, ticklen=2, showgrid=False,),
        yaxis=YAxis(       showgrid=False,
            zeroline=False,
            showline=False,
            showticklabels=False),
        
        annotations=annos,
        showlegend=False
    ),
       )

fig["layout"]["shapes"] = [
       shading(2008, 2012, color='#ff9980'),
       shading(2012, 2015.5, color='#99d6ff'),
       shading(2015.5, 2018, color='#dddd00'),
       ]
        
       
        
pl.iplot(fig)


Drawing...