diff --git a/_posts/python/scientific/dendrogram/2015-06-30-dendrograms.html b/_posts/python/scientific/dendrogram/2015-06-30-dendrograms.html index 7a921a3d279d..b509f064d03d 100644 --- a/_posts/python/scientific/dendrogram/2015-06-30-dendrograms.html +++ b/_posts/python/scientific/dendrogram/2015-06-30-dendrograms.html @@ -1,17 +1,17 @@ --- permalink: python/dendrogram/ -description: How to make a dendrogram in Python with Plotly. +description: How to make a dendrogram in Python with Plotly. name: Python Dendrograms has_thumbnail: true thumbnail: thumbnail/dendrogram.jpg -layout: user-guide name: Dendrograms -language: python title: Dendrograms | Plotly -display_as: scientific +language: python has_thumbnail: true -ipynb: ~notebook_demo/36 +display_as: scientific order: 6 +ipynb: ~notebook_demo/262 +layout: user-guide page_type: u-guide --- {% raw %} @@ -33,7 +33,7 @@
import plotly
+import plotly
plotly.__version__
@@ -53,7 +53,7 @@ Version Check
-'2.4.1'
+'3.4.2'
import plotly.plotly as py
-import plotly.figure_factory as ff
+import plotly.plotly as py
+import plotly.figure_factory as ff
-import numpy as np
+import numpy as np
X = np.random.rand(15, 15)
dendro = ff.create_dendrogram(X)
@@ -96,7 +96,7 @@ Basic Dendrogram
-Out[2]:
+Out[7]:
@@ -114,7 +114,7 @@ Basic Dendrogram
import plotly.plotly as py
-import plotly.figure_factory as ff
+import plotly.plotly as py
+import plotly.figure_factory as ff
-import numpy as np
+import numpy as np
+
+X = np.random.rand(15, 15)
+dendro = ff.create_dendrogram(X, color_threshold=1.5)
+dendro['layout'].update({'width':800, 'height':500})
+py.iplot(dendro, filename='simple_dendrogram_with_color_threshold')
+
+
+
import plotly.plotly as py
+import plotly.figure_factory as ff
+
+import numpy as np
X = np.random.rand(10, 10)
names = ['Jack', 'Oxana', 'John', 'Chelsea', 'Mark', 'Alice', 'Charlie', 'Rob', 'Lisa', 'Lily']
@@ -145,7 +193,7 @@ Set Orientation and Add Labels
-Out[3]:
+Out[4]:
@@ -172,17 +220,17 @@ Plot a Dendrogram with a HeatmapIn [5]:
import plotly.plotly as py
-import plotly.graph_objs as go
-import plotly.figure_factory as ff
+import plotly.plotly as py
+import plotly.graph_objs as go
+import plotly.figure_factory as ff
-import numpy as np
-from scipy.spatial.distance import pdist, squareform
+import numpy as np
+from scipy.spatial.distance import pdist, squareform
# get data
data = np.genfromtxt("http://files.figshare.com/2133304/ExpRawData_E_TABM_84_A_AFFY_44.tab",
- names=True,usecols=tuple(range(1,30)),dtype=float, delimiter="\t")
+ names=True,usecols=tuple(range(1,30)),dtype=float, delimiter="\t")
data_array = data.view((np.float, len(data.dtype.names)))
data_array = data_array.transpose()
labels = data.dtype.names
@@ -198,7 +246,8 @@ Plot a Dendrogram with a Heatmapdendro_side['data'][i]['xaxis'] = 'x2'
# Add Side Dendrogram Data to Figure
-figure['data'].extend(dendro_side['data'])
+for data in dendro_side['data']:
+ figure.add_trace(data)
# Create Heatmap
dendro_leaves = dendro_side['layout']['yaxis']['ticktext']
@@ -210,10 +259,10 @@ Plot a Dendrogram with a Heatmapheatmap = [
go.Heatmap(
- x = dendro_leaves,
+ x = dendro_leaves,
y = dendro_leaves,
- z = heat_data,
- colorscale = 'YIGnBu'
+ z = heat_data,
+ colorscale = 'Blues'
)
]
@@ -221,43 +270,44 @@ Plot a Dendrogram with a Heatmapheatmap[0]['y'] = dendro_side['layout']['yaxis']['tickvals']
# Add Heatmap Data to Figure
-figure['data'].extend(heatmap)
+for data in heatmap:
+ figure.add_trace(data)
# Edit Layout
figure['layout'].update({'width':800, 'height':800,
- 'showlegend':False, 'hovermode': 'closest',
+ 'showlegend':False, 'hovermode': 'closest',
})
# Edit xaxis
figure['layout']['xaxis'].update({'domain': [.15, 1],
- 'mirror': False,
- 'showgrid': False,
- 'showline': False,
- 'zeroline': False,
+ 'mirror': False,
+ 'showgrid': False,
+ 'showline': False,
+ 'zeroline': False,
'ticks':""})
# Edit xaxis2
figure['layout'].update({'xaxis2': {'domain': [0, .15],
- 'mirror': False,
- 'showgrid': False,
- 'showline': False,
- 'zeroline': False,
- 'showticklabels': False,
+ 'mirror': False,
+ 'showgrid': False,
+ 'showline': False,
+ 'zeroline': False,
+ 'showticklabels': False,
'ticks':""}})
# Edit yaxis
figure['layout']['yaxis'].update({'domain': [0, .85],
- 'mirror': False,
- 'showgrid': False,
- 'showline': False,
- 'zeroline': False,
- 'showticklabels': False,
+ 'mirror': False,
+ 'showgrid': False,
+ 'showline': False,
+ 'zeroline': False,
+ 'showticklabels': False,
'ticks': ""})
# Edit yaxis2
figure['layout'].update({'yaxis2':{'domain':[.825, .975],
- 'mirror': False,
- 'showgrid': False,
- 'showline': False,
- 'zeroline': False,
- 'showticklabels': False,
+ 'mirror': False,
+ 'showgrid': False,
+ 'showline': False,
+ 'zeroline': False,
+ 'showticklabels': False,
'ticks':""}})
# Plot!
@@ -293,7 +343,7 @@ Plot a Dendrogram with a HeatmapIn [6]:
-dendro_side['layout']['xaxis']
+dendro_side['layout']['xaxis']
@@ -312,14 +362,16 @@ Plot a Dendrogram with a Heatmap
-{'mirror': 'allticks',
- 'rangemode': 'tozero',
- 'showgrid': False,
- 'showline': True,
- 'showticklabels': True,
- 'ticks': 'outside',
- 'type': 'linear',
- 'zeroline': False}
+layout.XAxis({
+ 'mirror': 'allticks',
+ 'rangemode': 'tozero',
+ 'showgrid': False,
+ 'showline': True,
+ 'showticklabels': True,
+ 'ticks': 'outside',
+ 'type': 'linear',
+ 'zeroline': False
+})
@@ -338,10 +390,10 @@ Reference¶<
help(ff.create_dendrogram)
+help(ff.create_dendrogram)