Skip to content

Commit f8bd65d

Browse files
feat(matplotlib): implement heatmap-basic (#1380)
## Implementation: `heatmap-basic` - matplotlib Implements the **matplotlib** version of `heatmap-basic`. **File:** `plots/heatmap-basic/implementations/matplotlib.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20447951294)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 51ee5ca commit f8bd65d

2 files changed

Lines changed: 26 additions & 15 deletions

File tree

plots/heatmap-basic/implementations/matplotlib.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" pyplots.ai
22
heatmap-basic: Basic Heatmap
33
Library: matplotlib 3.10.8 | Python 3.13.11
4-
Quality: 95/100 | Created: 2025-12-14
4+
Quality: 94/100 | Created: 2025-12-23
55
"""
66

77
import matplotlib.pyplot as plt
@@ -19,16 +19,16 @@
1919
np.fill_diagonal(data, 1) # Perfect correlation on diagonal
2020
data = np.clip(data, -1, 1) # Clip to valid correlation range
2121

22-
# Create plot (4800x2700 px)
23-
fig, ax = plt.subplots(figsize=(16, 9))
22+
# Create plot (3600x3600 px - square format best for heatmaps)
23+
fig, ax = plt.subplots(figsize=(12, 12))
2424

2525
# Heatmap with diverging colormap for positive/negative values
26-
im = ax.imshow(data, cmap="RdBu_r", vmin=-1, vmax=1, aspect="auto")
26+
im = ax.imshow(data, cmap="RdBu_r", vmin=-1, vmax=1, aspect="equal")
2727

2828
# Add colorbar
2929
cbar = fig.colorbar(im, ax=ax, shrink=0.8, pad=0.02)
3030
cbar.ax.tick_params(labelsize=16)
31-
cbar.set_label("Correlation", fontsize=18)
31+
cbar.set_label("Correlation Coefficient", fontsize=18)
3232

3333
# Set ticks and labels
3434
ax.set_xticks(np.arange(n))
@@ -42,12 +42,12 @@
4242
value = data[i, j]
4343
# Use white text on dark cells, black on light cells
4444
text_color = "white" if abs(value) > 0.5 else "black"
45-
ax.text(j, i, f"{value:.2f}", ha="center", va="center", fontsize=14, color=text_color)
45+
ax.text(j, i, f"{value:.2f}", ha="center", va="center", fontsize=14, color=text_color, fontweight="bold")
4646

4747
# Labels and title
4848
ax.set_xlabel("Department", fontsize=20)
4949
ax.set_ylabel("Department", fontsize=20)
50-
ax.set_title("heatmap-basic · matplotlib · pyplots.ai", fontsize=24)
50+
ax.set_title("heatmap-basic · matplotlib · pyplots.ai", fontsize=24, pad=15)
5151

5252
plt.tight_layout()
5353
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
library: matplotlib
22
specification_id: heatmap-basic
3-
created: 2025-12-14 09:13:34+00:00
4-
updated: 2025-12-14 09:13:34+00:00
3+
created: '2025-12-23T00:46:03Z'
4+
updated: '2025-12-23T00:49:08Z'
55
generated_by: claude-opus-4-5-20251101
6-
workflow_run: 20205723953
7-
issue: 691
6+
workflow_run: 20447951294
7+
issue: 0
88
python_version: 3.13.11
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: 95
13+
quality_score: 94
1414
review:
15-
strengths: []
16-
weaknesses: []
17-
improvements: []
15+
strengths:
16+
- Excellent use of adaptive text colors (white on dark, black on light) for cell
17+
annotations ensuring readability
18+
- 'Perfect implementation of spec requirements: diverging colormap (RdBu_r), cell
19+
annotations, and colorbar'
20+
- Clean, symmetric correlation matrix with realistic department names providing
21+
meaningful context
22+
- Square aspect ratio (12×12) ideal for matrix visualization
23+
- Well-sized fonts throughout (24pt title, 20pt labels, 16pt ticks, 14pt annotations)
24+
weaknesses:
25+
- Could use matplotlib-specific features like ax.matshow() instead of ax.imshow()
26+
for more idiomatic matrix display
27+
- Department axis labels could include additional context (e.g., "Department" →
28+
"Department Correlation")

0 commit comments

Comments
 (0)