Gantt Chart in Python
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

I would like a Gantt chart like one of the ones here: https://plot.ly/python/gantt/. I would like to have vertical grid lines for the x values, similar to the pandas example in the above link. I would like an aesthetically pleasant color scheme but don't need to sort by an additional variable.

The timeline items would be:

  • January-Feb: V2 of website
  • March-Oct: Open walks
  • April: V1 discussion forum
  • May-June: Spring Expeditions
  • July: Assess expeditions
  • August-September: BRC talks and walks

Please include your code, bonus for using Jupyter Notebook so I can re-run your code.

awarded to s1cp

Crowdsource coding tasks.

3 Solutions

Winning solution

Chart: https://plot.ly/~mp12/0/gantt-chart/

Reversed chart: https://plot.ly/%7Emp12/4

Code:

import plotly.plotly as py
import plotly.figure_factory as ff


df = [dict(Task="V2 of website", Start='2018-01', Finish='2018-03', Complete=00),
      dict(Task="Open walks", Start='2018-03', Finish='2018-11', Complete=20),
      dict(Task="V1 discussion forum", Start='2018-04', Finish='2018-05', Complete=40),
      dict(Task="Spring Expeditions", Start='2018-05', Finish='2018-07', Complete=60),
      dict(Task="Assess expeditions", Start='2018-07', Finish='2018-08', Complete=80),
      dict(Task="BRC talks and walks", Start='2018-08', Finish='2018-10', Complete=99)]

colors = ["#62929e", "#546a7b"]

fig = ff.create_gantt(df, colors=colors, index_col='Complete', show_colorbar=True,
                      bar_width=0.2, showgrid_x=True, showgrid_y=True)
py.iplot(fig, filename='gantt-use-a-pandas-dataframe', world_readable=True)

Jupyter notebook file: https://gist.github.com/s1cp/4fc39f18c41a13130907cdbbc07bb2d9

Reversed: https://gist.github.com/s1cp/d58cde6e0c7b5df4031a1fb5b5ad8974

Awesome, dig it. Looks good--is there any chance you can flip the orientation so early things are on top?
msund 1 month ago

I have a version that works offline in Jupyter.

You will need to have plotly installed, which can be done with pip. Just tell me if you need any help installing it.

Here's the code:

import plotly.offline as py
import plotly.figure_factory as ff

py.init_notebook_mode(connected=True)

df = [dict(Task="V2 of<br>website",          Start='2018-01-01', Finish='2018-02-28'),
      dict(Task="Open<br>walks",             Start='2018-03-01', Finish='2018-10-31'),
      dict(Task="V1<br>discussion<br>forum", Start='2018-04-01', Finish='2018-04-30'),
      dict(Task="Spring<br>expeditions",     Start='2018-05-01', Finish='2018-06-30'),
      dict(Task="Assess<br>expeditions",     Start='2018-07-01', Finish='2018-07-31'),
      dict(Task="BRC talks<br>and walks",    Start='2018-08-01', Finish='2018-09-30')]

colors = ["#FCB711", "#F37021", "#CC004C", "#6460AA", "#0089D0", "#0DB14B"]

fig = ff.create_gantt(df[::-1], colors=colors[::-1], bar_width=0.25, showgrid_x=True)
py.iplot(fig)

Here's the resulting graph: https://imgur.com/UzWZlEp.png


import plotly.plotly as py
import plotly.figure_factory as ff
from plotly import tools

tools.set_credentials_file(username='<your_plotly_username>', api_key='<your_api_key>')

df = [dict(Task="V2 of website", Start='2018-01-01', Finish='2018-02-28', Resource='v2_of_website'),
      dict(Task="Open walks", Start='2018-03-01', Finish='2018-10-31', Resource='open_walks'),
      dict(Task="V1 discussion<br>forum", Start='2018-04-01', Finish='2018-04-28', Resource='v1_discussion_forum'),
      dict(Task="Spring<br>Expeditions", Start='2018-05-01', Finish='2018-06-30', Resource='spring_expeditions'),
      dict(Task="Assess<br>expeditions", Start='2018-07-01', Finish='2018-07-31', Resource='assess_expeditions'),
      dict(Task="BRC talks<br>and walks", Start='2018-08-01', Finish='2018-09-30', Resource='BRC_talks_and_walks')]
colors = dict(v2_of_website = 'rgb(0, 241, 185)',
              open_walks = 'rgb(69, 173, 98)',
              v1_discussion_forum = 'rgb(66, 134, 244)',
              spring_expeditions = 'rgb(242, 137, 0)',
              assess_expeditions = 'rgb(249, 249, 0)',
              BRC_talks_and_walks = 'rgb(220, 0, 0)')
fig = ff.create_gantt(df, colors=colors, index_col='Resource', show_colorbar=True)
py.iplot(fig, filename='gantt-dictioanry-colors', world_readable=True)

Here is the link to the Jupyter Notebook: https://plot.ly/~rawteech/6
You can get the API key from the settings section on your Plotly account.
If you need any help with that, I am readily available to jump in :-)

You can find the notebook file here: https://plot.ly/~rawteech/6
rawteech 1 month ago
View Timeline