Dendrogram

Gradient Fill Dendrogram Light

Light theme dendrogram with soft gradient background

Output
Gradient Fill Dendrogram Light
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='#ffffff')
ax.set_facecolor('#ffffff')

# Soft gradient background
gradient = np.linspace(0, 1, 256).reshape(1, -1)
cmap = LinearSegmentedColormap.from_list('bg', ['#ffffff', '#f0f9ff', '#ffffff'])
ax.imshow(gradient, extent=[0, 150, 0, max(Z[:,2])*1.1], aspect='auto', cmap=cmap, alpha=0.8, 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='#9ca3af', ax=ax)

ax.set_title('Gene Expression Clustering', fontsize=15, 
             color='#1f2937', fontweight='bold', pad=20)
ax.set_xlabel('Genes', fontsize=11, color='#374151')
ax.set_ylabel('Euclidean Distance', fontsize=11, color='#374151')
ax.tick_params(axis='both', colors='#374151', 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