Hey @cfriedline and @jmmease!
Here is the full and functionning example with offline plotly. I will post on Github using the link by @jmmease.
The three key lines are :
figure.add_traces(dendro_side[âdataâ])
figure.add_traces(heatmap)
plotly.offline.iplot(figure, filename=âdendrogram_with_heatmapâ)
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")
data_array = data.view((np.float, len(data.dtype.names)))
data_array = data_array.transpose()
labels = data.dtype.names
Initialize figure by creating upper dendrogram
figure = ff.create_dendrogram(data_array, orientation=âbottomâ, labels=labels)
for i in range(len(figure[âdataâ])):
figure[âdataâ][i][âyaxisâ] = ây2â
Create Side Dendrogram
dendro_side = ff.create_dendrogram(data_array, orientation=ârightâ)
for i in range(len(dendro_side[âdataâ])):
dendro_side[âdataâ][i][âxaxisâ] = âx2â
Add Side Dendrogram Data to Figure
figure.add_traces(dendro_side[âdataâ])
Create Heatmap
dendro_leaves = dendro_side[âlayoutâ][âyaxisâ][âticktextâ]
dendro_leaves = list(map(int, dendro_leaves))
data_dist = pdist(data_array)
heat_data = squareform(data_dist)
heat_data = heat_data[dendro_leaves,:]
heat_data = heat_data[:,dendro_leaves]
heatmap = [
go.Heatmap(
x = dendro_leaves,
y = dendro_leaves,
z = heat_data,
colorscale = âBluesâ
)
]
heatmap[0][âxâ] = figure[âlayoutâ][âxaxisâ][âtickvalsâ]
heatmap[0][âyâ] = dendro_side[âlayoutâ][âyaxisâ][âtickvalsâ]
figure.add_traces(heatmap)
Edit Layout
figure[âlayoutâ].update({âwidthâ:800, âheightâ:800,
âshowlegendâ:False, âhovermodeâ: âclosestâ,
})
Edit xaxisP
figure[âlayoutâ][âxaxisâ].update({âdomainâ: [.15, 1],
â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,
âticksâ:""}})
Edit yaxis
figure[âlayoutâ][âyaxisâ].update({âdomainâ: [0, .85],
â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,
âticksâ:""}})
Plot!
plotly.offline.iplot(figure, filename=âdendrogram_with_heatmapâ)