Skip to content

Commit 2c8e46d

Browse files
committed
gantt notebook
1 parent 7c9edb6 commit 2c8e46d

File tree

2 files changed

+56
-135
lines changed

2 files changed

+56
-135
lines changed

notebooks/gantt.md

Lines changed: 41 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
---
22
jupyter:
33
jupytext:
4+
notebook_metadata_filter: all
45
text_representation:
56
extension: .md
67
format_name: markdown
78
format_version: '1.1'
89
jupytext_version: 1.1.1
910
kernelspec:
10-
display_name: Python 2
11+
display_name: Python 3
1112
language: python
12-
name: python2
13+
name: python3
14+
language_info:
15+
codemirror_mode:
16+
name: ipython
17+
version: 3
18+
file_extension: .py
19+
mimetype: text/x-python
20+
name: python
21+
nbconvert_exporter: python
22+
pygments_lexer: ipython3
23+
version: 3.6.7
1324
plotly:
1425
description: How to make Gantt Charts in Python with Plotly. Gantt Charts use
1526
horizontal bars to represent the start and end times of tasks.
@@ -26,62 +37,40 @@ jupyter:
2637
title: Python Gantt Charts | plotly
2738
---
2839

29-
<!-- #region {"deletable": true, "editable": true} -->
30-
#### New to Plotly?
31-
Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/).
32-
<br>You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online).
33-
<br>We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!
34-
<!-- #endregion -->
35-
36-
<!-- #region {"deletable": true, "editable": true} -->
37-
#### Version Check
38-
Note: Gantt Charts are available in version <b>1.12.2+</b><br>
39-
Run `pip install plotly --upgrade` to update your Plotly version
40-
<!-- #endregion -->
41-
42-
```python deletable=true editable=true
43-
import plotly
44-
plotly.__version__
45-
```
40+
A [Gantt chart](https://en.wikipedia.org/wiki/Gantt_chart) is a type of bar chart that illustrates a project schedule. The chart lists the tasks to be performed on the vertical axis, and time intervals on the horizontal axis. The width of the horizontal bars in the graph shows the duration of each activity.
41+
42+
See also the [bar charts examples](https://plot.ly/python/bar-charts/).
43+
4644

47-
<!-- #region {"deletable": true, "editable": true} -->
4845
#### Simple Gantt Chart
49-
<!-- #endregion -->
5046

51-
```python deletable=true editable=true
52-
import plotly.plotly as py
47+
```python
5348
import plotly.figure_factory as ff
5449

5550
df = [dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28'),
5651
dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15'),
5752
dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30')]
5853

5954
fig = ff.create_gantt(df)
60-
py.iplot(fig, filename='gantt-simple-gantt-chart', world_readable=True)
55+
fig.show()
6156
```
6257

63-
<!-- #region {"deletable": true, "editable": true} -->
6458
#### Index by Numeric Variable
65-
<!-- #endregion -->
6659

67-
```python deletable=true editable=true
68-
import plotly.plotly as py
60+
```python
6961
import plotly.figure_factory as ff
7062

7163
df = [dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28', Complete=10),
7264
dict(Task="Job B", Start='2008-12-05', Finish='2009-04-15', Complete=60),
7365
dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30', Complete=95)]
7466

7567
fig = ff.create_gantt(df, colors='Viridis', index_col='Complete', show_colorbar=True)
76-
py.iplot(fig, filename='gantt-numeric-variable', world_readable=True)
68+
fig.show()
7769
```
7870

79-
<!-- #region {"deletable": true, "editable": true} -->
8071
#### Index by String Variable
81-
<!-- #endregion -->
8272

83-
```python deletable=true editable=true
84-
import plotly.plotly as py
73+
```python
8574
import plotly.figure_factory as ff
8675

8776
df = [dict(Task="Job A", Start='2009-01-01', Finish='2009-02-01', Resource='Apple'),
@@ -90,53 +79,42 @@ df = [dict(Task="Job A", Start='2009-01-01', Finish='2009-02-01', Resource='Appl
9079

9180
colors = ['#7a0504', (0.2, 0.7, 0.3), 'rgb(210, 60, 180)']
9281

93-
fig = ff.create_gantt(df, colors=colors, index_col='Resource', reverse_colors=True, show_colorbar=True)
94-
py.iplot(fig, filename='gantt-string-variable', world_readable=True)
82+
fig = ff.create_gantt(df, colors=colors, index_col='Resource', reverse_colors=True,
83+
show_colorbar=True)
84+
fig.show()
9585
```
9686

97-
<!-- #region {"deletable": true, "editable": true} -->
9887
#### Use a Dictionary for Colors
99-
<!-- #endregion -->
10088

101-
```python deletable=true editable=true
102-
import plotly.plotly as py
89+
```python
10390
import plotly.figure_factory as ff
10491

10592
df = [dict(Task="Job A", Start='2016-01-01', Finish='2016-01-02', Resource='Apple'),
10693
dict(Task="Job B", Start='2016-01-02', Finish='2016-01-04', Resource='Grape'),
10794
dict(Task="Job C", Start='2016-01-02', Finish='2016-01-03', Resource='Banana')]
10895

109-
colors = dict(Apple = 'rgb(220, 0, 0)',
110-
Grape = 'rgb(170, 14, 200)',
111-
Banana = (1, 0.9, 0.16))
96+
colors = dict(Apple='rgb(220, 0, 0)', Grape='rgb(170, 14, 200)', Banana=(1, 0.9, 0.16))
11297

11398
fig = ff.create_gantt(df, colors=colors, index_col='Resource', show_colorbar=True)
114-
py.iplot(fig, filename='gantt-dictioanry-colors', world_readable=True)
99+
fig.show()
115100
```
116101

117-
<!-- #region {"deletable": true, "editable": true} -->
118102
#### Use a Pandas Dataframe
119-
<!-- #endregion -->
120103

121-
```python deletable=true editable=true
122-
import plotly.plotly as py
104+
```python
123105
import plotly.figure_factory as ff
124106

125107
import pandas as pd
126-
127108
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gantt_example.csv')
128109

129-
fig = ff.create_gantt(df, colors=['#333F44', '#93e4c1'], index_col='Complete', show_colorbar=True,
130-
bar_width=0.2, showgrid_x=True, showgrid_y=True)
131-
py.iplot(fig, filename='gantt-use-a-pandas-dataframe', world_readable=True)
110+
fig = ff.create_gantt(df, colors=['#333F44', '#93e4c1'], index_col='Complete',
111+
show_colorbar=True, bar_width=0.2, showgrid_x=True, showgrid_y=True)
112+
fig.show()
132113
```
133114

134-
<!-- #region {"deletable": true, "editable": true} -->
135115
#### Using Hours and Minutes in Times
136-
<!-- #endregion -->
137116

138-
```python deletable=true editable=true
139-
import plotly.plotly as py
117+
```python
140118
import plotly.figure_factory as ff
141119

142120
df = [
@@ -160,13 +138,12 @@ colors = dict(Cardio = 'rgb(46, 137, 205)',
160138

161139
fig = ff.create_gantt(df, colors=colors, index_col='Resource', title='Daily Schedule',
162140
show_colorbar=True, bar_width=0.8, showgrid_x=True, showgrid_y=True)
163-
py.iplot(fig, filename='gantt-hours-minutes', world_readable=True)
141+
fig.show()
164142
```
165143

166144
#### Group Tasks Together
167145

168146
```python
169-
import plotly.plotly as py
170147
import plotly.figure_factory as ff
171148

172149
df = [dict(Task="Job-1", Start='2017-01-01', Finish='2017-02-02', Resource='Complete'),
@@ -182,37 +159,18 @@ colors = {'Not Started': 'rgb(220, 0, 0)',
182159
'Incomplete': (1, 0.9, 0.16),
183160
'Complete': 'rgb(0, 255, 100)'}
184161

185-
fig = ff.create_gantt(df, colors=colors, index_col='Resource', show_colorbar=True, group_tasks=True)
186-
py.iplot(fig, filename='gantt-group-tasks-together', world_readable=True)
162+
fig = ff.create_gantt(df, colors=colors, index_col='Resource', show_colorbar=True,
163+
group_tasks=True)
164+
fig.show()
187165
```
188166

189-
<!-- #region {"deletable": true, "editable": true} -->
190167
#### Reference
191-
For info on Plotly Range Slider and Selector, see: https://plot.ly/python/reference/#layout-xaxis-rangeselector.
192-
<!-- #endregion -->
193168

194-
```python deletable=true editable=true
195-
help(ff.create_gantt)
196-
```
197169

198-
```python deletable=true editable=true
199-
from IPython.display import display, HTML
200-
201-
display(HTML('<link href="//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Inconsolata|Ubuntu+Mono:400,700" rel="stylesheet" type="text/css" />'))
202-
display(HTML('<link rel="stylesheet" type="text/css" href="http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css">'))
203-
204-
! pip install git+https://github.com/plotly/publisher.git --upgrade
205-
import publisher
206-
publisher.publish(
207-
'gantt.ipynb', 'python/gantt/', 'Python Gantt Charts | plotly',
208-
'How to make Gantt Charts in Python with Plotly. Gantt Charts use horizontal bars to represent the start and end times of tasks.',
209-
title='Python Gantt Charts | plotly',
210-
name='Gantt Charts',
211-
thumbnail='thumbnail/gantt.jpg', language='python',
212-
has_thumbnail='true', display_as='basic', order=5.5,
213-
ipynb= '~notebook_demo/6')
170+
```python
171+
help(ff.create_gantt)
214172
```
215173

216-
```python deletable=true editable=true
174+
```python
217175

218-
```
176+
```

notebooks/network-graphs.md

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
jupyter:
33
jupytext:
4+
notebook_metadata_filter: all
45
text_representation:
56
extension: .md
67
format_name: markdown
@@ -26,46 +27,29 @@ jupyter:
2627
thumbnail: thumbnail/net.jpg
2728
---
2829

29-
#### New to Plotly?
30-
Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/).
31-
<br>You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online).
32-
<br>We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!# Network Graphs with Plotly.
30+
In this example we show how to visualize a network graph created using `networkx`.
3331

34-
Install the Python library `networkx` with `sudo pip install networkx`.
32+
Install the Python library `networkx` with `pip install networkx`.
3533

3634

37-
#### Get Node Positions
38-
Store position as node attribute data for random_geometric_graph and find node near center (0.5, 0.5)
35+
36+
### Create random graph
3937

4038
```python
41-
import plotly.plotly as py
4239
import plotly.graph_objs as go
4340

4441
import networkx as nx
4542

46-
G=nx.random_geometric_graph(200,0.125)
47-
pos=nx.get_node_attributes(G,'pos')
48-
49-
dmin=1
50-
ncenter=0
51-
for n in pos:
52-
x,y=pos[n]
53-
d=(x-0.5)**2+(y-0.5)**2
54-
if d<dmin:
55-
ncenter=n
56-
dmin=d
57-
58-
p=nx.single_source_shortest_path_length(G,ncenter)
43+
G = nx.random_geometric_graph(200, 0.125)
5944
```
6045

6146
#### Create Edges
6247
Add edges as disconnected lines in a single trace and nodes as a scatter trace
6348

6449
```python
6550
edge_trace = go.Scatter(
66-
x=[],
67-
y=[],
68-
line=dict(width=0.5,color='#888'),
51+
x=[], y=[],
52+
line=dict(width=0.5, color='#888'),
6953
hoverinfo='none',
7054
mode='lines')
7155

@@ -97,7 +81,7 @@ node_trace = go.Scatter(
9781
xanchor='left',
9882
titleside='right'
9983
),
100-
line=dict(width=2)))
84+
line_width=2))
10185

10286
for node in G.nodes():
10387
x, y = G.node[node]['pos']
@@ -113,9 +97,9 @@ i.e. ```node_trace['marker']['size'].append(len(adjacencies))```
11397

11498
```python
11599
for node, adjacencies in enumerate(G.adjacency()):
116-
node_trace['marker']['color']+=tuple([len(adjacencies[1])])
100+
node_trace['marker']['color'] += tuple([len(adjacencies[1])])
117101
node_info = '# of connections: '+str(len(adjacencies[1]))
118-
node_trace['text']+=tuple([node_info])
102+
node_trace['text'] += tuple([node_info])
119103
```
120104

121105
#### Create Network Graph
@@ -124,7 +108,7 @@ for node, adjacencies in enumerate(G.adjacency()):
124108
fig = go.Figure(data=[edge_trace, node_trace],
125109
layout=go.Layout(
126110
title='<br>Network graph made with Python',
127-
titlefont=dict(size=16),
111+
titlefont_size=16,
128112
showlegend=False,
129113
hovermode='closest',
130114
margin=dict(b=20,l=5,r=5,t=40),
@@ -134,9 +118,9 @@ fig = go.Figure(data=[edge_trace, node_trace],
134118
xref="paper", yref="paper",
135119
x=0.005, y=-0.002 ) ],
136120
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
137-
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False)))
138-
139-
py.iplot(fig, filename='networkx')
121+
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False))
122+
)
123+
fig.show()
140124
```
141125

142126
### Dash Example
@@ -157,24 +141,3 @@ IFrame(src= "https://dash-simple-apps.plotly.host/dash-networkplot/code", width=
157141
#### Reference
158142
See https://plot.ly/python/reference/#scatter for more information and chart attribute options!
159143

160-
```python
161-
from IPython.display import display, HTML
162-
163-
display(HTML('<link href="//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Inconsolata|Ubuntu+Mono:400,700" rel="stylesheet" type="text/css" />'))
164-
display(HTML('<link rel="stylesheet" type="text/css" href="http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css">'))
165-
166-
! pip install git+https://github.com/plotly/publisher.git --upgrade
167-
import publisher
168-
publisher.publish(
169-
'networkx.ipynb', 'python/network-graphs/', 'Python Network Graphs',
170-
'How to make Network Graphs in Python with Plotly. '
171-
'One examples of a network graph with NetworkX',
172-
name = 'Network Graphs',
173-
thumbnail='thumbnail/net.jpg', language='python',
174-
has_thumbnail='true', display_as='scientific', order=14, redirect_from='ipython-notebooks/networks/',
175-
ipynb= '~notebook_demo/223')
176-
```
177-
178-
```python
179-
180-
```

0 commit comments

Comments
 (0)