Python中的 plotly.figure_factory.create_dendrogram()函数
Python的 Plotly 库对于数据可视化和简单轻松地理解数据非常有用。
plotly.figure_factory.create_dendrogram
树状图是表示树的图。名为 create_dendrogram 的图形工厂对数据执行层次聚类并表示生成的树。树深度轴上的值对应于簇之间的距离。
Syntax: plotly.figure_factory.create_dendrogram(X, orientation=’bottom’, labels=None, colorscale=None, distfun=None, linkagefun=
Parameter:
X ((ndarray)) – it describes the matrix of observations as array of arrays
orientation ((str)) – in this we use ‘top’, ‘right’, ‘bottom’, or ‘left’
labels ((list)) – it describes the list of axis category labels(observation labels)
colorscale ((list)) – it describes the optional colorscale for dendrogram tree
distfun ((function)) – it describes the function to compute the pairwise distance from the observations
linkagefun ((function)) – it describes the function to compute the linkage matrix from the pairwise distances
hovertext ((list[list])) – it describes the list of hovertext for constituent traces of dendrogram clusters
color_threshold ((double)) – it describes the value at which the separation of clusters will be made
示例 1:简单的面向底部的树状图
Python3
from plotly.figure_factory import create_dendrogram
import numpy as np
X = np.random.rand(10,10)
fig = create_dendrogram(X)
fig.show()
Python3
from plotly.figure_factory import create_dendrogram
import numpy as np
X = np.random.rand(5,5)
names = ['Jack', 'Oxana', 'John', 'Chelsea', 'Mark']
dendro = create_dendrogram(X, orientation='right', labels=names)
dendro.update_layout({'width':700, 'height':500})
dendro.show()
输出:
示例 2:放置在热图左侧的树状图
Python3
from plotly.figure_factory import create_dendrogram
import numpy as np
X = np.random.rand(5,5)
names = ['Jack', 'Oxana', 'John', 'Chelsea', 'Mark']
dendro = create_dendrogram(X, orientation='right', labels=names)
dendro.update_layout({'width':700, 'height':500})
dendro.show()
输出: