Plotly Create_Dendogram()

A dendrogram is a specific type of plot represented as a tree. It is commonly used in hierarchical data that allows you to visualize the data as a hierarchy.

We can use the create_dendrogram() function from the Plotly.figure_factory to create a dendrogram plot.


The function provides a syntax as shown in the following:

plotly.figure_factory.create_dendrogram (X, orientation='bottom', labels=None, colorscale=None, distfun=None, linkagefun=<function <lambda>>, hovertext=None, color_threshold=None)

The parameter functionality is as follows:

  1. x – Specifies the matrix of observations as an array of arrays.
  2. orientation – Sets the orientation of the plot. Accepted values include:
    1. ‘top’
    2. ‘right’
    3. ‘bottom’
    4. ‘left’
  3. colorscale – Sets a colorscale for the dendrogram figure.
  4. distfun – Represents the function used to calculate the pairwise distance from the observations.
  5. linkagefun – Sets the function to determine the linkage matrix from the pairwise distance.
  6. hovertext – Sets the hover text for the traces of the dendrogram cluster.
  7. color_threshold – Defines the value used to make the separation of the clusters.

Example 1:

The following code shows how to create a simple dendrogram tree with the orientation set to bottom.

import plotly.figure_factory as ff
import numpy as np
x = np.random.rand(10,10)
fig = ff.create_dendrogram(x, orientation='bottom')

The previous code returns a dendrogram plot as in the following figure:

You can change the orientation to any value that suits your needs.

Example 2:

You can also set the labels for the dendrogram by specifying the labels parameter.

x = np.random.rand(10,10)
chars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
fig = ff.create_dendrogram(x, orientation='left', labels=chars)



This article covers the basics of creating a dendrogram figure in Plotly.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list