Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 39 additions & 21 deletions plots/heatmap-basic/implementations/seaborn.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" pyplots.ai
heatmap-basic: Basic Heatmap
Library: seaborn 0.13.2 | Python 3.13.11
Quality: 93/100 | Created: 2025-12-23
Library: seaborn 0.13.2 | Python 3.14.3
Quality: 92/100 | Updated: 2026-02-15
"""

import matplotlib.pyplot as plt
Expand All @@ -24,35 +24,53 @@
# Clip to valid performance range
data = np.clip(data, 5, 95)

# Plot - using square format for heatmap
fig, ax = plt.subplots(figsize=(12, 12))
sns.heatmap(
# Plot - clustermap groups similar departments via hierarchical clustering
g = sns.clustermap(
data,
annot=True,
fmt=".0f",
cmap="RdBu",
cmap="coolwarm",
center=50,
xticklabels=months,
yticklabels=departments,
linewidths=1,
linewidths=1.5,
linecolor="white",
cbar_kws={"label": "Performance Score", "shrink": 0.75},
annot_kws={"fontsize": 16},
ax=ax,
annot_kws={"fontsize": 16, "fontweight": "medium"},
figsize=(16, 10),
row_cluster=True,
col_cluster=False,
dendrogram_ratio=0.08,
cbar_pos=(0.02, 0.15, 0.03, 0.6),
cbar_kws={"label": "Performance Score", "ticks": [0, 25, 50, 75, 100]},
vmin=0,
vmax=100,
)
Comment on lines +27 to 47
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using sns.clustermap() with hierarchical clustering is inappropriate for a "basic" heatmap specification. The specification for heatmap-basic asks for a simple matrix heatmap with logical ordering (alphabetical, by magnitude, or by similarity), not hierarchical clustering with dendrograms. Clustering functionality is the defining feature of the separate heatmap-clustered specification. This implementation should use sns.heatmap() instead, similar to the matplotlib implementation and the heatmap-correlation seaborn implementation. The current approach violates the principle that each specification should demonstrate a distinct plot type.

Copilot uses AI. Check for mistakes.

# Style
ax.set_xlabel("Month", fontsize=20)
ax.set_ylabel("Department", fontsize=20)
ax.set_title("heatmap-basic · seaborn · pyplots.ai", fontsize=24, pad=20)
ax.tick_params(axis="both", labelsize=16)
# Colorbar styling
g.cax.set_ylabel("Performance Score", fontsize=18, labelpad=10)
g.cax.tick_params(labelsize=14)
g.cax.yaxis.set_label_position("left")

# Adjust colorbar label size
cbar = ax.collections[0].colorbar
cbar.ax.tick_params(labelsize=14)
cbar.ax.set_ylabel("Performance Score", fontsize=18)
# Labels and title
g.ax_heatmap.set_xlabel("Month", fontsize=20, labelpad=12)
g.ax_heatmap.set_ylabel("Department", fontsize=20, labelpad=12)
g.ax_heatmap.tick_params(axis="x", labelsize=16)
g.ax_heatmap.tick_params(axis="y", labelsize=16, rotation=0)

plt.tight_layout()
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
# Visual refinement - remove heatmap spines for cleaner look
for spine in g.ax_heatmap.spines.values():
spine.set_visible(False)

# Style the dendrogram
g.ax_row_dendrogram.set_facecolor("#f8f8f8")
for spine in g.ax_row_dendrogram.spines.values():
spine.set_visible(False)

# Background refinement
g.fig.patch.set_facecolor("#fafafa")
g.ax_heatmap.set_facecolor("white")

# Title
g.fig.suptitle("heatmap-basic · seaborn · pyplots.ai", fontsize=24, fontweight="medium", y=1.02, color="#333333")

plt.savefig("plot.png", dpi=300, bbox_inches="tight", facecolor=g.fig.get_facecolor())
Loading