Dendrogram

Pastel Zone Bands Light

Light dendrogram with pastel colored zone bands

Output
Pastel Zone Bands Light
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy.cluster.hierarchy import dendrogram, linkage, set_link_color_palette

np.random.seed(456)

labels = ['Sample_' + chr(65+i) for i in range(14)]
data = np.random.rand(len(labels), 4) * 80
Z = linkage(data, method='ward')

fig, ax = plt.subplots(figsize=(14, 8), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

# Pastel horizontal bands
zone_colors = ['#F5276C15', '#27D3F515', '#6CF52715', '#F5B02715']
max_dist = max(Z[:,2])
for i, color in enumerate(zone_colors):
    ax.axhspan(i*max_dist/4, (i+1)*max_dist/4, color=color, zorder=0)

set_link_color_palette(['#F5276C', '#27D3F5', '#6CF527', '#F5B027'])

dn = dendrogram(Z, labels=labels, leaf_rotation=45, leaf_font_size=11,
                color_threshold=0.55*max(Z[:,2]), above_threshold_color='#9ca3af', ax=ax)

ax.set_title('Hierarchical Clustering with Distance Zones', fontsize=15, 
             color='#1f2937', fontweight='bold', pad=20)
ax.set_xlabel('Samples', fontsize=11, color='#374151')
ax.set_ylabel('Ward Distance', fontsize=11, color='#374151')
ax.tick_params(axis='both', colors='#374151', labelsize=10)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#e5e7eb')
ax.spines['bottom'].set_color('#e5e7eb')

# Zone labels
for i, label in enumerate(['Low', 'Medium', 'High', 'Very High']):
    ax.text(-2, (i+0.5)*max_dist/4, label, color='#6b7280', fontsize=8, va='center', ha='right')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support