Skip to content

Commit 9d68333

Browse files
update(heatmap-basic): matplotlib — comprehensive quality review
Comprehensive quality review: fix weaknesses from prior reviews, preserve strengths, improve quality across all dimensions.
1 parent 89f6f3b commit 9d68333

4 files changed

Lines changed: 52 additions & 33 deletions

File tree

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,71 @@
1-
""" pyplots.ai
1+
"""pyplots.ai
22
heatmap-basic: Basic Heatmap
3-
Library: matplotlib 3.10.8 | Python 3.13.11
4-
Quality: 94/100 | Created: 2025-12-23
3+
Library: matplotlib 3.10.8 | Python 3.14.3
4+
Quality: /100 | Updated: 2026-02-15
55
"""
66

77
import matplotlib.pyplot as plt
88
import numpy as np
9+
from matplotlib.colors import TwoSlopeNorm
910

1011

11-
# Data - correlation-like matrix with meaningful labels
12-
np.random.seed(42)
13-
categories = ["Sales", "Marketing", "Support", "Dev", "HR", "Finance", "Ops", "Legal"]
14-
n = len(categories)
12+
# Data - department correlation matrix with realistic patterns
13+
departments = ["Sales", "Marketing", "Support", "Dev", "HR", "Finance", "Ops", "Legal"]
14+
n = len(departments)
1515

16-
# Generate a correlation-like symmetric matrix
17-
raw = np.random.randn(n, n)
18-
data = (raw + raw.T) / 2 # Make symmetric
19-
np.fill_diagonal(data, 1) # Perfect correlation on diagonal
20-
data = np.clip(data, -1, 1) # Clip to valid correlation range
16+
# Craft realistic correlations: related departments correlate more strongly
17+
data = np.array(
18+
[
19+
[1.00, 0.82, 0.35, 0.12, -0.05, 0.61, 0.44, 0.08], # Sales
20+
[0.82, 1.00, 0.28, 0.18, 0.10, 0.48, 0.30, 0.05], # Marketing
21+
[0.35, 0.28, 1.00, 0.55, 0.22, -0.10, 0.60, 0.15], # Support
22+
[0.12, 0.18, 0.55, 1.00, 0.08, -0.25, 0.42, -0.12], # Dev
23+
[-0.05, 0.10, 0.22, 0.08, 1.00, 0.30, 0.18, 0.52], # HR
24+
[0.61, 0.48, -0.10, -0.25, 0.30, 1.00, 0.35, 0.40], # Finance
25+
[0.44, 0.30, 0.60, 0.42, 0.18, 0.35, 1.00, 0.20], # Ops
26+
[0.08, 0.05, 0.15, -0.12, 0.52, 0.40, 0.20, 1.00], # Legal
27+
]
28+
)
2129

22-
# Create plot (3600x3600 px - square format best for heatmaps)
30+
# Plot (square format for matrix visualization)
2331
fig, ax = plt.subplots(figsize=(12, 12))
2432

25-
# Heatmap with diverging colormap for positive/negative values
26-
im = ax.imshow(data, cmap="RdBu_r", vmin=-1, vmax=1, aspect="equal")
33+
# Heatmap with diverging colormap centered at zero
34+
norm = TwoSlopeNorm(vmin=-1, vcenter=0, vmax=1)
35+
im = ax.matshow(data, cmap="RdBu_r", norm=norm)
2736

28-
# Add colorbar
29-
cbar = fig.colorbar(im, ax=ax, shrink=0.8, pad=0.02)
37+
# Colorbar
38+
cbar = fig.colorbar(im, ax=ax, shrink=0.78, pad=0.02, aspect=30)
3039
cbar.ax.tick_params(labelsize=16)
31-
cbar.set_label("Correlation Coefficient", fontsize=18)
40+
cbar.set_label("Correlation Coefficient", fontsize=18, labelpad=12)
41+
cbar.outline.set_visible(False)
3242

33-
# Set ticks and labels
43+
# Tick labels
3444
ax.set_xticks(np.arange(n))
3545
ax.set_yticks(np.arange(n))
36-
ax.set_xticklabels(categories, fontsize=16, rotation=45, ha="right")
37-
ax.set_yticklabels(categories, fontsize=16)
46+
ax.set_xticklabels(departments, fontsize=16, rotation=45, ha="left")
47+
ax.set_yticklabels(departments, fontsize=16)
48+
ax.xaxis.set_ticks_position("bottom")
49+
ax.tick_params(axis="both", length=0)
3850

39-
# Add value annotations in cells
51+
# Cell value annotations with adaptive text color
4052
for i in range(n):
4153
for j in range(n):
4254
value = data[i, j]
43-
# Use white text on dark cells, black on light cells
44-
text_color = "white" if abs(value) > 0.5 else "black"
55+
text_color = "white" if abs(value) > 0.55 else "black"
4556
ax.text(j, i, f"{value:.2f}", ha="center", va="center", fontsize=14, color=text_color, fontweight="bold")
4657

58+
# Subtle cell borders
59+
for i in range(n + 1):
60+
ax.axhline(i - 0.5, color="white", linewidth=1.5)
61+
ax.axvline(i - 0.5, color="white", linewidth=1.5)
62+
4763
# Labels and title
48-
ax.set_xlabel("Department", fontsize=20)
49-
ax.set_ylabel("Department", fontsize=20)
50-
ax.set_title("heatmap-basic · matplotlib · pyplots.ai", fontsize=24, pad=15)
64+
ax.set_xlabel("Department", fontsize=20, labelpad=12)
65+
ax.set_ylabel("Department", fontsize=20, labelpad=12)
66+
ax.set_title(
67+
"Department Correlation · heatmap-basic · matplotlib · pyplots.ai", fontsize=24, fontweight="medium", pad=15
68+
)
5169

5270
plt.tight_layout()
5371
plt.savefig("plot.png", dpi=300, bbox_inches="tight")

plots/heatmap-basic/metadata/matplotlib.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
library: matplotlib
22
specification_id: heatmap-basic
33
created: '2025-12-23T00:46:03Z'
4-
updated: '2025-12-23T00:49:08Z'
5-
generated_by: claude-opus-4-5-20251101
4+
updated: '2026-02-15T21:25:00+00:00'
5+
generated_by: claude-opus-4-6
66
workflow_run: 20447951294
77
issue: 0
8-
python_version: 3.13.11
8+
python_version: 3.14.3
99
library_version: 3.10.8
1010
preview_url: https://storage.googleapis.com/pyplots-images/plots/heatmap-basic/matplotlib/plot.png
1111
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/heatmap-basic/matplotlib/plot_thumb.png
1212
preview_html: null
13-
quality_score: 94
13+
quality_score: null
1414
impl_tags:
1515
dependencies: []
1616
techniques:

plots/heatmap-basic/specification.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ A heatmap displaying values in a matrix format using color intensity. Each cell'
2323
- Use a diverging colormap for data with positive/negative values
2424
- Add value annotations in cells when readable
2525
- Include a colorbar legend
26-
- Consider clustering rows/columns for better pattern visibility
26+
- Order rows/columns logically (alphabetical, by magnitude, or by similarity)

plots/heatmap-basic/specification.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: Basic Heatmap
66

77
# Specification tracking
88
created: 2025-12-14T09:02:34Z
9-
updated: 2025-12-14T09:02:34Z
9+
updated: 2026-02-15T12:00:00Z
1010
issue: 691
1111
suggested: MarkusNeusinger
1212

@@ -18,6 +18,7 @@ tags:
1818
data_type:
1919
- numeric
2020
- categorical
21+
- matrix
2122
domain:
2223
- statistics
2324
- general

0 commit comments

Comments
 (0)