-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisuals.py
More file actions
60 lines (48 loc) · 1.8 KB
/
Copy pathvisuals.py
File metadata and controls
60 lines (48 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import matplotlib.pyplot as plt
from permutations import deconvert_matrix_to_str
def visualize_sdk(sudoku: str | list[list[str]], inital_grid: str = '', title: str = ''):
"""
:param inital_grid: inital grid to be plotted in different color.
:param sudoku: can be both 81 length string or matrix
:param title: if you want
:return: creates a grid of cells.
"""
if type(sudoku) != str:
sudoku = deconvert_matrix_to_str(sudoku)
rows, cols = 9, 9
fig, ax = plt.subplots()
for x in range(cols + 1):
if x % 3 == 0 or x in [0, 9]:
ax.axvline(x, lw=3, color='black', zorder=5)
else:
ax.axvline(x, lw=1, color='black', zorder=5)
for y in range(rows + 1):
if y % 3 == 0 or y in [0, 9]:
ax.axhline(y, lw=3, color='black', zorder=5)
else:
ax.axhline(y, lw=1, color='black', zorder=5)
for i in range(rows):
for j in range(cols):
if inital_grid != '' and inital_grid[i * 9 + j] not in ['X', 0, '0']:
# Draw original grid values in black
ax.text(
j + 0.5, i + 0.5,
inital_grid[i * 9 + j],
ha="center", va="center", fontsize=15, color="black"
)
elif sudoku[i * 9 + j] not in ['X', 0, '0']:
# Draw solved/updated values in blue
ax.text(
j + 0.5, i + 0.5,
sudoku[i * 9 + j],
ha="center", va="center", fontsize=15, color="blue"
)
# need to rotate bc its 0 0 at bottom left
ax.set_xlim(0, cols)
ax.set_ylim(0, rows)
ax.set_aspect('equal')
ax.set_xticklabels("")
ax.set_yticklabels("")
ax.set_title(title)
ax.invert_yaxis()
plt.show()