📅  最后修改于: 2023-12-03 15:34:24.249000             🧑  作者: Mango
The plotly.figure_factory.create_dendrogram()
function in Python is used for creating a dendrogram plot. A dendrogram is a hierarchical representation of objects. This function helps to visualize the hierarchical clustering of objects in a tree-like diagram.
The syntax for the plotly.figure_factory.create_dendrogram()
function is as follows:
plotly.figure_factory.create_dendrogram(data, orientation='bottom', labels=None)
Here,
data
represents the input data. It could be a distance matrix or a linkage matrix.orientation
is used to set the orientation of the dendrogram. By default, it is set to 'bottom' which shows the root of the tree at the bottom.labels
is an optional parameter that can be used to label the leaves of the dendrogram. If labels
is set to None
, the dendrogram shows the indices of the data points.import plotly.figure_factory as ff
import numpy as np
# Generate random matrix
matrix = np.random.rand(15, 12)
# Create dendrogram
dendro = ff.create_dendrogram(matrix)
# Add labels
dendro['layout'].update({'width':600, 'height':400})
dendro['layout']['xaxis']['tickfont'] = {'size':14,'color':'rgb(86, 86, 86)'}
dendro['layout']['yaxis']['tickfont'] = {'size':14,'color':'rgb(86, 86, 86)'}
# Display dendrogram
fig = ff.create_dendrogram(matrix)
fig.update_layout(width=800, height=500)
fig.show()
In the above example, we first generate a random matrix of size (15, 12)
. We then create a dendrogram using ff.create_dendrogram()
function. Finally, we add labels to the dendrogram using the layout
attribute of the dendrogram object and display it using fig.show()
function.
In summary, plotly.figure_factory.create_dendrogram()
function in Python is a very useful tool for visualizing hierarchical clustering of objects in a dendrogram format. It provides a quick and easy way to analyze the relationships between data points in a hierarchical clustering context. The function is simple to use and produces visually appealing dendrograms that make it easy to analyze the relationships between data points.