Clustermap
Sports Team Statistics
Player performance metrics clustered by playing style
Output
Python
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
np.random.seed(666)
stats = ['Points', 'Assists', 'Rebounds', 'Steals', 'Blocks',
'FG%', '3PT%', 'FT%', 'Minutes', 'Turnovers']
players = ['LeBron', 'Curry', 'Durant', 'Giannis', 'Jokic', 'Embiid',
'Tatum', 'Doncic', 'Morant', 'Edwards', 'Booker', 'Mitchell']
data = np.random.rand(10, 12) * 15 + 10
data[0, :4] += 15
data[1, [1, 7]] += 10
data[2, 3:6] += 8
data[4, 3:6] += 6
df = pd.DataFrame(data, index=stats, columns=players)
styles = ['All-around']*2 + ['Scorer']*2 + ['Big']*2 + ['Two-way']*3 + ['Athletic']*3
style_palette = {'All-around': '#6366f1', 'Scorer': '#ef4444', 'Big': '#f59e0b',
'Two-way': '#22c55e', 'Athletic': '#ec4899'}
col_colors = pd.Series(styles, index=players).map(style_palette)
light_cmap = LinearSegmentedColormap.from_list('sports', ['#f8fafc', '#bfdbfe', '#6366f1', '#312e81'])
g = sns.clustermap(df, cmap=light_cmap, col_colors=col_colors,
method='average', metric='euclidean', standard_scale=0,
linewidths=0.5, linecolor='#e5e7eb',
figsize=(10, 8), dendrogram_ratio=(0.12, 0.12),
cbar_pos=(0.01, 0.08, 0.008, 0.12))
g.fig.patch.set_facecolor('#ffffff')
g.ax_heatmap.set_facecolor('#ffffff')
g.ax_heatmap.tick_params(colors='#1f2937', labelsize=8)
g.ax_row_dendrogram.set_facecolor('#ffffff')
g.ax_col_dendrogram.set_facecolor('#ffffff')
g.cax.tick_params(colors='#1f2937', labelsize=7)
g.fig.suptitle('NBA Player Statistics', color='#1f2937', fontsize=13, fontweight='bold', y=1.02)
plt.show()
Library
Matplotlib
Category
Heatmaps & Density
More Clustermap examples
☕