Dendrogram

Music Genre Clustering Light

Music genre similarity with vibrant neon colors

Output
Music Genre Clustering 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(321)

genres = ['Rock', 'Metal', 'Jazz', 'Blues', 'Classical', 'Electronic',
          'Hip-Hop', 'R&B', 'Country', 'Folk', 'Pop', 'Reggae', 'Soul']

audio_features = np.random.rand(len(genres), 7) * 100
Z = linkage(audio_features, method='average')

fig, ax = plt.subplots(figsize=(13, 7), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

set_link_color_palette(['#F527B0', '#27D3F5', '#6CF527', '#F5D327', '#4927F5'])

dn = dendrogram(Z, labels=genres, leaf_rotation=40, leaf_font_size=11,
                color_threshold=0.7*max(Z[:,2]), above_threshold_color='#d1d5db', ax=ax)

ax.set_title('Music Genre Similarity Analysis', fontsize=15, 
             color='#1f2937', fontweight='bold', pad=18)
ax.set_xlabel('Genre', fontsize=11, color='#374151')
ax.set_ylabel('Audio Feature Distance', fontsize=11, color='#374151')

ax.tick_params(axis='both', colors='#374151', labelsize=10)
for spine in ['top', 'right']:
    ax.spines[spine].set_visible(False)
for spine in ['left', 'bottom']:
    ax.spines[spine].set_color('#e5e7eb')
ax.yaxis.grid(True, color='#f3f4f6', linewidth=0.5)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support