Clustermap

Survey Response Patterns

Employee satisfaction survey responses clustered by department

Output
Survey Response Patterns
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(222)

questions = ['Work-Life', 'Compensation', 'Growth', 'Management', 'Culture',
             'Benefits', 'Recognition', 'Training', 'Communication', 'Resources']
departments = ['Engineering', 'Sales', 'Marketing', 'HR', 'Finance', 'Support', 'Product', 'Legal']

data = np.random.rand(10, 8) * 3 + 2
data[9, 0] += 2
data[6, 0] -= 1
data[1, 1] += 2

df = pd.DataFrame(data, index=questions, columns=departments)

dept_size = ['Large']*3 + ['Medium']*3 + ['Small']*2
size_palette = {'Large': '#6366f1', 'Medium': '#22c55e', 'Small': '#f59e0b'}
col_colors = pd.Series(dept_size, index=departments).map(size_palette)

light_cmap = LinearSegmentedColormap.from_list('survey', ['#fef2f2', '#fef9c3', '#dcfce7', '#22c55e'])

g = sns.clustermap(df, cmap=light_cmap, vmin=1, vmax=5, 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('Employee Survey Analysis', 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