Clustermap
Student Performance Matrix
Academic performance across subjects with student clustering
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(444)
subjects = ['Math', 'Physics', 'Chemistry', 'Biology', 'English',
'History', 'Geography', 'Art', 'Music', 'PE']
students = [f'Student_{i}' for i in range(1, 16)]
data = np.random.rand(10, 15) * 40 + 50
data[:4, :5] += 20
data[4:7, 5:10] += 15
data[7:9, 10:] += 25
df = pd.DataFrame(data, index=subjects, columns=students)
types = ['STEM']*5 + ['Humanities']*5 + ['Arts']*5
type_palette = {'STEM': '#3b82f6', 'Humanities': '#8b5cf6', 'Arts': '#ec4899'}
col_colors = pd.Series(types, index=students).map(type_palette)
light_cmap = LinearSegmentedColormap.from_list('grades', ['#fef2f2', '#fef9c3', '#dcfce7', '#22c55e'])
g = sns.clustermap(df, cmap=light_cmap, vmin=40, vmax=100, col_colors=col_colors,
method='ward', metric='euclidean',
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('Student Academic Performance', color='#1f2937', fontsize=13, fontweight='bold', y=1.02)
plt.show()
Library
Matplotlib
Category
Heatmaps & Density
More Clustermap examples
☕