Skip to content

Commit 7d0bd9f

Browse files
committed
tree-plots
1 parent 4d68915 commit 7d0bd9f

File tree

1 file changed

+27
-52
lines changed

1 file changed

+27
-52
lines changed

notebooks/tree-plots.md

Lines changed: 27 additions & 52 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 interactive tree-plot in Python with Plotly. An examples
1526
of a tree-plot in Plotly.
@@ -25,28 +36,15 @@ jupyter:
2536
title: Python Tree-plots | plotly
2637
---
2738

28-
#### New to Plotly?
29-
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/).
30-
<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).
31-
<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!
32-
39+
#### Set Up Tree with [igraph](http://igraph.org/python/)
3340

34-
#### Basic Tree-Plot in Plotly with [igraph](http://igraph.org/python/)
41+
Install igraph with `pip install python-igraph`.
3542

3643
```python
37-
import plotly.plotly as py
38-
import plotly.graph_objs as go
39-
4044
import igraph
41-
from igraph import *
42-
igraph.__version__
43-
```
44-
45-
#### Set Up Tree with [igraph](http://igraph.org/python/)
46-
47-
```python
45+
from igraph import Graph, EdgeSeq
4846
nr_vertices = 25
49-
v_label = map(str, range(nr_vertices))
47+
v_label = list(map(str, range(nr_vertices)))
5048
G = Graph.Tree(nr_vertices, 2) # 2 stands for children number
5149
lay = G.layout('rt')
5250

@@ -72,6 +70,7 @@ labels = v_label
7270
#### Create Plotly Traces
7371

7472
```python
73+
import plotly.graph_objs as go
7574
lines = go.Scatter(x=Xe,
7675
y=Ye,
7776
mode='lines',
@@ -81,8 +80,8 @@ lines = go.Scatter(x=Xe,
8180
dots = go.Scatter(x=Xn,
8281
y=Yn,
8382
mode='markers',
84-
name='',
85-
marker=dict(symbol='dot',
83+
name='bla',
84+
marker=dict(symbol='circle-dot',
8685
size=18,
8786
color='#6175c1', #'#DB4551',
8887
line=dict(color='rgb(50,50,50)', width=1)
@@ -100,10 +99,10 @@ def make_annotations(pos, text, font_size=10, font_color='rgb(250,250,250)'):
10099
L=len(pos)
101100
if len(text)!=L:
102101
raise ValueError('The lists pos and text must have the same len')
103-
annotations = go.Annotations()
102+
annotations = []
104103
for k in range(L):
105104
annotations.append(
106-
go.Annotation(
105+
dict(
107106
text=labels[k], # or replace labels with a different list for the text within the circle
108107
x=pos[k][0], y=2*M-position[k][1],
109108
xref='x1', yref='y1',
@@ -124,10 +123,10 @@ axis = dict(showline=False, # hide axis line, grid, ticklabels and title
124123

125124
layout = dict(title= 'Tree with Reingold-Tilford Layout',
126125
annotations=make_annotations(position, v_label),
127-
font=dict(size=12),
126+
font_size=12,
128127
showlegend=False,
129-
xaxis=go.XAxis(axis),
130-
yaxis=go.YAxis(axis),
128+
xaxis=axis,
129+
yaxis=axis,
131130
margin=dict(l=40, r=40, b=85, t=100),
132131
hovermode='closest',
133132
plot_bgcolor='rgb(248,248,248)'
@@ -137,34 +136,10 @@ layout = dict(title= 'Tree with Reingold-Tilford Layout',
137136
#### Plot!
138137

139138
```python
140-
data=go.Data([lines, dots])
141-
fig=dict(data=data, layout=layout)
142-
fig['layout'].update(annotations=make_annotations(position, v_label))
143-
py.iplot(fig, filename='Tree-Reingold-Tilf')
139+
fig=go.Figure(data=[lines, dots], layout=layout)
140+
fig.show()
144141
```
145142

146143
#### Reference
147144
See https://plot.ly/python/reference/ for more information and chart attribute options and http://igraph.org/python/ for more information about the igraph package!
148145

149-
```python
150-
from IPython.display import display, HTML
151-
152-
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" />'))
153-
display(HTML('<link rel="stylesheet" type="text/css" href="http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css">'))
154-
155-
! pip install git+https://github.com/plotly/publisher.git --upgrade
156-
import publisher
157-
publisher.publish(
158-
'tree-plot.ipynb', 'python/tree-plots/', 'Python Tree-plots | plotly',
159-
'How to make interactive tree-plot in Python with Plotly. '
160-
'An examples of a tree-plot in Plotly.',
161-
title = 'Python Tree-plots | plotly',
162-
name = 'Tree-plots',
163-
thumbnail='thumbnail/treeplot.jpg', language='python',
164-
page_type='example_index', has_thumbnail='true', display_as='statistical', order=10.5,
165-
ipynb= '~notebook_demo/28')
166-
```
167-
168-
```python
169-
170-
```

0 commit comments

Comments
 (0)