-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchessboard.py
41 lines (34 loc) · 1.11 KB
/
chessboard.py
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
from matplotlib import pyplot as plt
from matplotlib import colors
# In this script can create a chessboard pattern with two or many colours
def make_matrix(x, y):
"""Creates a sizex by sizey matrix filled with zeros."""
return [[0]*y for _ in range(x)]
dimension = 8
chessboard = make_matrix(dimension, dimension)
# Here you can chose the colours to use in the image.
# Here there are a list of colours: ["white", "green", "black", "orange", "blue", "yellow", "red", "pink"]
colours_grid = ["white", "black"]
colours = range(len(colours_grid))
# Create the chessboard pattern
counter = 0
for i in range(dimension):
for j in range(dimension):
chessboard[i][j] = counter
counter += 1
if counter == len(colours):
counter = 0
counter += 1
if counter == len(colours):
counter = 0
#print(chessboard)
# Plot the data
# Set the colours
Cmap = colors.ListedColormap(colours_grid)
# Show the image
plt.figure(figsize=(20, 20))
plt.imshow(chessboard, cmap=Cmap)
plt.xticks(color='w')
plt.yticks(color='w')
#plt.savefig("media/chessboard.png", format="png", dpi=300)
plt.show()