|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | 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 |
5 | 5 | """ |
6 | 6 |
|
7 | | -import matplotlib.patches as patches |
| 7 | +import os |
| 8 | + |
8 | 9 | import matplotlib.pyplot as plt |
9 | 10 | import numpy as np |
10 | 11 | import seaborn as sns |
11 | 12 |
|
12 | 13 |
|
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) |
14 | 22 | grid = np.array( |
15 | 23 | [ |
16 | 24 | [5, 3, 0, 0, 7, 0, 0, 0, 0], |
|
24 | 32 | [0, 0, 0, 0, 8, 0, 0, 7, 9], |
25 | 33 | ] |
26 | 34 | ) |
| 35 | +clue_mask = (grid > 0).astype(float) |
| 36 | +annotations = np.where(grid == 0, "", grid.astype(str)) |
27 | 37 |
|
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 | +) |
34 | 51 |
|
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) |
37 | 54 |
|
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`. |
39 | 57 | 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], |
43 | 62 | cbar=False, |
44 | | - linewidths=1, |
45 | | - linecolor="#CCCCCC", |
| 63 | + linewidths=1.2, |
| 64 | + linecolor=INK_SOFT, |
46 | 65 | square=True, |
47 | 66 | xticklabels=False, |
48 | 67 | yticklabels=False, |
49 | 68 | vmin=0, |
50 | 69 | vmax=1, |
| 70 | + annot_kws={"size": 34, "weight": "bold", "color": INK}, |
| 71 | + ax=ax, |
51 | 72 | ) |
52 | 73 |
|
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) |
78 | 78 |
|
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) |
83 | 81 | ax.set_xticks([]) |
84 | 82 | ax.set_yticks([]) |
85 | | - |
86 | | -# Set axis limits |
87 | 83 | ax.set_xlim(0, 9) |
88 | 84 | ax.set_ylim(9, 0) |
89 | 85 |
|
90 | 86 | 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