Skip to content

Commit bc6af63

Browse files
feat(seaborn): implement sudoku-basic (#5346)
## Implementation: `sudoku-basic` - python/seaborn Implements the **python/seaborn** version of `sudoku-basic`. **File:** `plots/sudoku-basic/implementations/python/seaborn.py` **Parent Issue:** #1311 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/24881196244)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent ac61546 commit bc6af63

2 files changed

Lines changed: 201 additions & 182 deletions

File tree

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
sudoku-basic: Basic Sudoku Grid
3-
Library: seaborn 0.13.2 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-23
3+
Library: seaborn 0.13.2 | Python 3.14.4
4+
Quality: 90/100 | Updated: 2026-04-24
55
"""
66

7-
import matplotlib.patches as patches
7+
import os
8+
89
import matplotlib.pyplot as plt
910
import numpy as np
1011
import seaborn as sns
1112

1213

13-
# Sudoku puzzle data (0 = empty cell)
14+
# Theme tokens
15+
THEME = os.getenv("ANYPLOT_THEME", "light")
16+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
17+
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
18+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
19+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
20+
21+
# Data (classic Sudoku puzzle; 0 = empty cell)
1422
grid = np.array(
1523
[
1624
[5, 3, 0, 0, 7, 0, 0, 0, 0],
@@ -24,68 +32,56 @@
2432
[0, 0, 0, 0, 8, 0, 0, 7, 9],
2533
]
2634
)
35+
clue_mask = (grid > 0).astype(float)
36+
annotations = np.where(grid == 0, "", grid.astype(str))
2737

28-
# Set seaborn style for clean aesthetic
29-
sns.set_style("white")
30-
sns.set_context("talk", font_scale=1.5)
31-
32-
# Create square figure (3600x3600 px at 300 dpi = 12x12 inches)
33-
fig, ax = plt.subplots(figsize=(12, 12))
38+
# Theme-adaptive seaborn chrome
39+
sns.set_theme(
40+
style="white",
41+
rc={
42+
"figure.facecolor": PAGE_BG,
43+
"axes.facecolor": PAGE_BG,
44+
"axes.edgecolor": INK,
45+
"axes.labelcolor": INK,
46+
"text.color": INK,
47+
"xtick.color": INK_SOFT,
48+
"ytick.color": INK_SOFT,
49+
},
50+
)
3451

35-
# Create heatmap data for visual structure (all white for clean look)
36-
display_grid = np.ones((9, 9))
52+
# Plot
53+
fig, ax = plt.subplots(figsize=(12, 12), facecolor=PAGE_BG)
3754

38-
# Use seaborn heatmap as the base grid structure
55+
# Seaborn renders the full grid: cell fills (subtle clue vs. empty contrast),
56+
# thin cell separators, and the digits themselves via `annot`.
3957
sns.heatmap(
40-
display_grid,
41-
ax=ax,
42-
cmap=["white"],
58+
clue_mask,
59+
annot=annotations,
60+
fmt="",
61+
cmap=[PAGE_BG, ELEVATED_BG],
4362
cbar=False,
44-
linewidths=1,
45-
linecolor="#CCCCCC",
63+
linewidths=1.2,
64+
linecolor=INK_SOFT,
4665
square=True,
4766
xticklabels=False,
4867
yticklabels=False,
4968
vmin=0,
5069
vmax=1,
70+
annot_kws={"size": 34, "weight": "bold", "color": INK},
71+
ax=ax,
5172
)
5273

53-
# Add numbers to the grid
54-
for i in range(9):
55-
for j in range(9):
56-
if grid[i, j] != 0:
57-
ax.text(
58-
j + 0.5,
59-
i + 0.5,
60-
str(grid[i, j]),
61-
ha="center",
62-
va="center",
63-
fontsize=32,
64-
fontweight="bold",
65-
color="#306998",
66-
)
67-
68-
# Draw thick lines for 3x3 box boundaries
69-
for i in range(4):
70-
# Horizontal thick lines
71-
ax.axhline(y=i * 3, color="black", linewidth=4)
72-
# Vertical thick lines
73-
ax.axvline(x=i * 3, color="black", linewidth=4)
74-
75-
# Add border rectangle for clean edges
76-
border = patches.Rectangle((0, 0), 9, 9, linewidth=4, edgecolor="black", facecolor="none")
77-
ax.add_patch(border)
74+
# Thick 3x3 box boundaries (full outer frame + interior dividers)
75+
for k in range(4):
76+
ax.axhline(y=k * 3, color=INK, linewidth=5, clip_on=False)
77+
ax.axvline(x=k * 3, color=INK, linewidth=5, clip_on=False)
7878

79-
# Title
80-
ax.set_title("sudoku-basic · seaborn · pyplots.ai", fontsize=28, fontweight="bold", pad=20, color="#306998")
81-
82-
# Remove axis ticks
79+
# Style
80+
ax.set_title("sudoku-basic · seaborn · anyplot.ai", fontsize=24, fontweight="medium", color=INK, pad=24)
8381
ax.set_xticks([])
8482
ax.set_yticks([])
85-
86-
# Set axis limits
8783
ax.set_xlim(0, 9)
8884
ax.set_ylim(9, 0)
8985

9086
plt.tight_layout()
91-
plt.savefig("plot.png", dpi=300, bbox_inches="tight", facecolor="white")
87+
plt.savefig(f"plot-{THEME}.png", dpi=300, bbox_inches="tight", facecolor=PAGE_BG)

0 commit comments

Comments
 (0)