Dendrogram
Truncated Dendrogram
Condensed view showing major clusters only
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy.cluster.hierarchy import dendrogram, linkage, set_link_color_palette
np.random.seed(321)
data = np.random.randn(50, 8)
Z = linkage(data, method='ward')
fig, ax = plt.subplots(figsize=(10, 7), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')
set_link_color_palette(['#F5B027', '#27D3F5', '#F5276C', '#6CF527'])
dn = dendrogram(Z, truncate_mode='lastp', p=8, leaf_font_size=11,
color_threshold=15, above_threshold_color='#444444', ax=ax,
show_leaf_counts=True)
ax.set_title('Truncated Cluster View (8 Major Groups)', color='white', fontsize=14, fontweight='bold', pad=15)
ax.set_xlabel('Cluster Size', color='#888888', fontsize=11)
ax.set_ylabel('Distance', color='#888888', fontsize=11)
ax.tick_params(axis='both', colors='white', labelsize=10)
for spine in ax.spines.values():
spine.set_color('#333333')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More Dendrogram examples
☕