from plotly.offline import download_plotlyjs, init_notebook_mode, iplot, plot
init_notebook_mode(connected=True)
Plot a Gantt chart:
import plotly.figure_factory as ff
from datetime import datetime
df = [dict(Task="Job A", Start='2009-01-01', Finish='2009-02-01', Resource='Apple'),
dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15', Resource='Grape'),
dict(Task="Job C", Start='2009-04-20', Finish='2009-09-30', Resource='Banana')]
colors = ['#7a0504', (0.2, 0.7, 0.3), 'rgb(210, 60, 180)']
fig = ff.create_gantt(df, colors=colors, index_col='Resource', reverse_colors=True, show_colorbar=True)
iplot(fig)
Inspect fig['data']
and fig['layout']
in case you want to update some dicts:
fig['data']
[{'marker': {'color': 'white'}, 'name': '', 'x': ['2009-01-01', '2009-02-01'], 'y': [0, 0]}, {'marker': {'color': 'white'}, 'name': '', 'x': ['2009-03-05', '2009-04-15'], 'y': [1, 1]}, {'marker': {'color': 'white'}, 'name': '', 'x': ['2009-04-20', '2009-09-30'], 'y': [2, 2]}, {'hoverinfo': 'none', 'marker': {'color': 'rgb(210, 60, 180)', 'size': 1}, 'name': 'Apple', 'showlegend': True, 'x': ['2009-04-20', '2009-04-20'], 'y': [0, 0]}, {'hoverinfo': 'none', 'marker': {'color': 'rgb(51, 178, 76)', 'size': 1}, 'name': 'Banana', 'showlegend': True, 'x': ['2009-04-20', '2009-04-20'], 'y': [1, 1]}, {'hoverinfo': 'none', 'marker': {'color': 'rgb(122, 5, 4)', 'size': 1}, 'name': 'Grape', 'showlegend': True, 'x': ['2009-04-20', '2009-04-20'], 'y': [2, 2]}]
fig['layout']
{'height': 600, 'hovermode': 'closest', 'shapes': [{'fillcolor': 'rgb(210, 60, 180)', 'line': {'width': 0}, 'opacity': 1, 'type': 'rect', 'x0': '2009-01-01', 'x1': '2009-02-01', 'xref': 'x', 'y0': -0.2, 'y1': 0.2, 'yref': 'y'}, {'fillcolor': 'rgb(122, 5, 4)', 'line': {'width': 0}, 'opacity': 1, 'type': 'rect', 'x0': '2009-03-05', 'x1': '2009-04-15', 'xref': 'x', 'y0': 0.8, 'y1': 1.2, 'yref': 'y'}, {'fillcolor': 'rgb(51, 178, 76)', 'line': {'width': 0}, 'opacity': 1, 'type': 'rect', 'x0': '2009-04-20', 'x1': '2009-09-30', 'xref': 'x', 'y0': 1.8, 'y1': 2.2, 'yref': 'y'}], 'showlegend': True, 'title': 'Gantt Chart', 'width': 900, 'xaxis': {'rangeselector': {'buttons': [{'count': 7, 'label': '1w', 'step': 'day', 'stepmode': 'backward'}, {'count': 1, 'label': '1m', 'step': 'month', 'stepmode': 'backward'}, {'count': 6, 'label': '6m', 'step': 'month', 'stepmode': 'backward'}, {'count': 1, 'label': 'YTD', 'step': 'year', 'stepmode': 'todate'}, {'count': 1, 'label': '1y', 'step': 'year', 'stepmode': 'backward'}, {'step': 'all'}]}, 'showgrid': False, 'type': 'date', 'zeroline': False}, 'yaxis': {'autorange': False, 'range': [-1, 4], 'showgrid': False, 'ticktext': ['Job A', 'Job B', 'Job C'], 'tickvals': [0, 1, 2], 'zeroline': False}}
fig['data'] is a list of dicts, while fig['layout'] is just one dict. Hence you should append a new dict to fig['data'] in order to insert another trace (scatter plot, for example).
yaxis range is [-1, 4]. In a new scatter trace you can plot points and lines connecting them, having datetime as x-coordinates and y-coords between [-1,4]. If you want to extend yaxis range in the Gantt chart, perform an update like this one:
fig['layout']['yaxis'].update(range=[-1,6])
scatter_trace=dict(type='scatter',
x=[datetime(2009, 6, 13), datetime(2009, 7, 13)],
y=[1, 3])
fig['data'].append(scatter_trace)
iplot(fig)