python-scipyHow do I create a dendrogram using Python and SciPy?
The dendrogram is a graphical representation of a hierarchical structure (e.g. a tree) that is commonly used to represent the relationships between data points in a dataset. It can be created using Python and SciPy with the following steps:
- Import the necessary libraries:
 
import scipy.cluster.hierarchy as sch
from matplotlib import pyplot as plt
- Create the data to be used in the dendrogram. For example, a 2x3 matrix:
 
data = [[2, 3, 4], [5, 6, 7]]
- Use the SciPy library to generate the linkage matrix:
 
Z = sch.linkage(data, 'ward')
- Generate the dendrogram using the linkage matrix:
 
dendrogram = sch.dendrogram(Z)
- Plot the dendrogram:
 
plt.show()
The resulting dendrogram will look like this:

Helpful links
More of Python Scipy
- How do I use Scipy zeros in Python?
 - How do I create a 2D array of zeros using Python and NumPy?
 - How do I use Python XlsxWriter to write a NumPy array to an Excel file?
 - How to use Python, XML-RPC, and NumPy together?
 - How do I use Python Numpy to read and write Excel (.xlsx) files?
 - How can I check if a certain version of Python is compatible with SciPy?
 - How can I install and use SciPy on Ubuntu?
 - How do I create a QQ plot using Python and SciPy?
 - How do I create an array of zeros with the same shape as an existing array using Python and NumPy?
 - How can I use Python and SciPy to find the zeros of a function?
 
See more codes...