Clustermap

Product Feature Comparison

Feature ratings across competing products

Output
Product Feature Comparison
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(555)

features = ['Performance', 'Battery', 'Display', 'Camera', 'Storage',
            'Build Quality', 'Software', 'Price Value', 'Support', 'Ecosystem']
products = ['iPhone 15', 'Galaxy S24', 'Pixel 8', 'OnePlus 12', 'Xiaomi 14',
            'Sony Xperia', 'Asus ROG', 'Nothing Phone']

data = np.random.rand(10, 8) * 3 + 5
data[9, 0] += 2
data[0, 6] += 2
data[7, 4:6] += 1.5

df = pd.DataFrame(data, index=features, columns=products)

tiers = ['Premium']*3 + ['Mid-range']*3 + ['Gaming'] + ['Budget']
tier_palette = {'Premium': '#6366f1', 'Mid-range': '#22c55e', 'Gaming': '#ef4444', 'Budget': '#f59e0b'}
col_colors = pd.Series(tiers, index=products).map(tier_palette)

light_cmap = LinearSegmentedColormap.from_list('rating', ['#fee2e2', '#fef9c3', '#d1fae5', '#059669'])

g = sns.clustermap(df, cmap=light_cmap, vmin=5, vmax=10, col_colors=col_colors,
                   method='average', metric='euclidean',
                   linewidths=0.5, linecolor='#e5e7eb',
                   figsize=(9, 8), dendrogram_ratio=(0.12, 0.12),
                   annot=True, fmt='.1f', annot_kws={'size': 8, 'color': '#374151'},
                   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('Smartphone Feature Comparison', color='#1f2937', fontsize=13, fontweight='bold', y=1.02)
plt.show()
Library

Matplotlib

Category

Heatmaps & Density

Did this help you?

Support PyLucid to keep it free & growing

Support