Dendrogram

Gradient Fill Dendrogram Dark

Dendrogram with gradient-filled background areas

Output
Gradient Fill Dendrogram Dark
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy.cluster.hierarchy import dendrogram, linkage, set_link_color_palette
from matplotlib.colors import LinearSegmentedColormap

np.random.seed(123)

labels = ['Gene_' + str(i) for i in range(1, 16)]
data = np.random.rand(len(labels), 6) * 50
Z = linkage(data, method='average')

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

# Gradient background
gradient = np.linspace(0, 1, 256).reshape(1, -1)
cmap = LinearSegmentedColormap.from_list('bg', ['#0a0a0f', '#1a1a3f', '#0a0a0f'])
ax.imshow(gradient, extent=[0, 150, 0, max(Z[:,2])*1.1], aspect='auto', cmap=cmap, alpha=0.5, zorder=0)

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

dn = dendrogram(Z, labels=labels, leaf_rotation=45, leaf_font_size=10,
                color_threshold=0.6*max(Z[:,2]), above_threshold_color='#555555', ax=ax)

ax.set_title('Gene Expression Clustering with Gradient Background', fontsize=15, 
             color='white', fontweight='bold', pad=20)
ax.set_xlabel('Genes', fontsize=11, color='#888888')
ax.set_ylabel('Euclidean Distance', fontsize=11, color='#888888')
ax.tick_params(axis='both', colors='#888888', labelsize=9)
for spine in ax.spines.values():
    spine.set_visible(False)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support