import pandas as pd import plotly.plotly as py from plotly.graph_objs import * help(Figure) help(Data) help(Layout) help(Scatter) pasajeros = pd.io.excel.read_excel('07-Heathrow_Monthly_Traffic_Statistics_(Jan_2005-Jul_2014).xls', sheetname=0, # tomamos la primera hoja del archivo header=2, # la cebecera empieza en la fila 3 index_col=0) # empleamos las fechas como indices pasajeros.head(5) mercancias = pd.io.excel.read_excel('07-Heathrow_Monthly_Traffic_Statistics_(Jan_2005-Jul_2014).xls', sheetname=5, # tomamos la sexta hoja del archivo header=2, # la cebecera empieza en la fila 3 index_col=0) # empleamos las fechas como indices mercancias.head(5) pasajeros.to_period('M').head(2) p_data = Data([Scatter(name=col, x=pasajeros.index, y=pasajeros[col], mode='lines') for col in pasajeros.columns.values[:4]]) p_layout = Layout(title='Tráfico mensual de pasajeros en aeropuertos del grupo Heathrow', xaxis=XAxis(title='Mes', showgrid=False, showline=True, mirror='ticks', linewidth=2), yaxis=YAxis(title='Pasajeros', zeroline=False, showline=True, mirror='ticks', linewidth=2), margin=Margin(r=20, t=80)) p_fig = Figure(data=p_data, layout=p_layout) p_plot = py.iplot(p_fig, filename='pybonacci/heathrow-pasajeros') m_data = Data([Scatter(name=col, x=mercancias.index, y=mercancias[col], mode='lines') for col in pasajeros.columns.values[:4]]) m_layout = Layout(title='Tráfico mensual de mercancías en aeropuertos del grupo Heathrow', xaxis=XAxis(title='Mes', showgrid=False, showline=True, mirror='ticks', linewidth=2), yaxis=YAxis(title='Mercancías (t)', zeroline=False, showline=True, mirror='ticks', lineheight=2), margin=Margin(r=20, t=80)) m_layout = dict(title='Tráfico mensual de mercancías en aeropuertos del grupo Heathrow', xaxis=dict(title='Mes', showgrid=False, showline=True, mirror='ticks', linewidth=2), yaxis=dict(title='Mercancías (t)', zeroline=False, showline=True, mirror='ticks', linewidth=2), margin=dict(r=20, t=80)) m_fig = Figure(data=m_data, layout=m_layout) m_plot = py.iplot(m_fig, filename='pybonacci/heathrow-mercancias') import calendar import numpy as np gb = lambda x: x.month data = Data([Heatmap(x=np.arange(2005,2015), y=calendar.month_abbr[1:], z=[grp['Heathrow'] for key, grp in pasajeros.groupby(gb)], colorscale='Portland')]) layout = Layout(title='Tráfico de pasajeros en el aeropuerto de Heathrow', autosize=False, width=550, height=550, xaxis=XAxis(title='Año', showgrid=False), yaxis=YAxis(title='Mes', showgrid=False)) heatmap_plot = py.iplot(Figure(data=data,layout=layout), filename='pybonacci/heathrow-heatmap') data = Data([Box(name=calendar.month_abbr[key], y=grp['Heathrow'].values, boxpoints='all') for key, grp in mercancias.groupby(gb)]) layout = Layout(title='Tráfico de mercancías en el aeropuerto de Heathrow (2005-2014)', showlegend=False, margin=Margin(r=20, t=90)) box_plot = py.iplot(Figure(data=data, layout=layout), filename='pybonacci/heathrow-box') pas = Scatter(name='Pasajeros', x=pasajeros.index, y=pasajeros['Glasgow'], yaxis='y2', mode='lines+markers', line=Line(shape='hv', color='darkgoldenrod'), marker=Marker(color='goldenrod', line=Line(color='darkgoldenrod', width=2))) mer = Bar(name='Mercancías', x=pasajeros.index, y=mercancias['Glasgow'], marker=Marker(color='lightgray')) data = Data([mer, pas]) layout = Layout(title='Tráfico de pasajeros y mercancías en el aeropuerto de Glasgow', showlegend=False, xaxis=XAxis(title='Mes'), yaxis=YAxis(title='Mercancías (t)', showgrid=False), yaxis2=YAxis(title='Pasajeros', showgrid=False, overlaying='y', side='right')) fuente = Annotation(text="Fuente: LHR Airports Limited", xref='paper', # empleamos coordenadas 'paper', con ello la nota no se moverá al mover los ejes. yref='paper', x=0, y=-0.15, showarrow=False) layout.update(annotations=Annotations([fuente])) ma_plot = py.iplot(Figure(data=data, layout=layout), filename='pybonacci/heathrow-multipleaxis')