Dendrogram
Neon Glow Clusters Dark
Dendrogram with neon glow effect on cluster areas
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy.cluster.hierarchy import dendrogram, linkage, fcluster, set_link_color_palette
from matplotlib.patches import Rectangle, FancyBboxPatch
np.random.seed(789)
labels = ['Node_' + str(i) for i in range(1, 13)]
data = np.random.rand(len(labels), 5) * 60
Z = linkage(data, method='complete')
fig, ax = plt.subplots(figsize=(14, 8), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')
set_link_color_palette(['#F5276C', '#27D3F5', '#6CF527', '#F5B027'])
dn = dendrogram(Z, labels=labels, leaf_rotation=0, leaf_font_size=11,
color_threshold=0.5*max(Z[:,2]), above_threshold_color='#444444', ax=ax)
# Add glowing cluster boxes
clusters = fcluster(Z, t=4, criterion='maxclust')
glow_colors = [('#F5276C', '#F5276C22'), ('#27D3F5', '#27D3F522'),
('#6CF527', '#6CF52722'), ('#F5B027', '#F5B02722')]
ivl = dn['ivl']
leaves = dn['leaves']
cluster_ranges = {}
for i, leaf in enumerate(leaves):
c = clusters[leaf]
if c not in cluster_ranges:
cluster_ranges[c] = [i, i]
else:
cluster_ranges[c][1] = i
for c, (start, end) in cluster_ranges.items():
edge_color, fill_color = glow_colors[(c-1) % len(glow_colors)]
# Glow effect with multiple rectangles
for offset, alpha in [(3, 0.1), (2, 0.15), (1, 0.2)]:
rect = FancyBboxPatch((start*10 - 5 - offset, -offset),
(end - start + 1)*10 + 2*offset,
max(Z[:,2])*0.9 + 2*offset,
boxstyle='round,pad=0.02', facecolor=fill_color,
edgecolor=edge_color, linewidth=0.5, alpha=alpha, zorder=0)
ax.add_patch(rect)
ax.set_title('Network Clustering with Neon Glow Effect', fontsize=15,
color='white', fontweight='bold', pad=20)
ax.set_xlabel('Nodes', fontsize=11, color='#888888')
ax.set_ylabel('Distance', fontsize=11, color='#888888')
ax.tick_params(axis='both', colors='#888888', labelsize=10)
for spine in ax.spines.values():
spine.set_visible(False)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More Dendrogram examples
☕