from matplotlib.patches import Wedge
from matplotlib.collections import PatchCollection, LineCollection
def square(x, y, orientation=1, marksize=0.1, linewidth=0.5):
deg = lambda dx, dy: 90 * orientation -45 + 180 * ((dx + dy + 1) % 2)
black_wedges = PatchCollection([Wedge((x + dx, y + dy), marksize,
deg(dx, dy) + 90, deg(dx, dy) - 90)
for dx in [-0.5, 0.5] for dy in [-0.5, 0.5]],
color='black', zorder=2)
white_wedges = PatchCollection([Wedge((x + dx, y + dy), marksize,
deg(dx, dy) - 90, deg(dx, dy) + 90)
for dx in [-0.5, 0.5] for dy in [-0.5, 0.5]],
color='#EEEEEE', zorder=2)
vertices = [[-0.5, -0.5], [-0.5, 0.5], [0.5, 0.5], [0.5, -0.5]]
offsets = [[1.05], [0.95], [1.05]]
black_verts = (x, y) + np.roll(vertices, 4 - orientation, axis=0)[:3] * offsets
white_verts = (x, y) + np.roll(vertices, 2 - orientation, axis=0)[:3] * offsets
black_lines = LineCollection([black_verts],
color='black', zorder=1, linewidth=linewidth)
white_lines = LineCollection([white_verts],
color='#EEEEEE', zorder=1, linewidth=linewidth)
return black_wedges, white_wedges, black_lines, white_lines
fig, ax = plt.subplots(figsize=(8, 8))
fig.subplots_adjust(left=0, right=1, bottom=0, top=1)
for x in range(23):
for y in range(23):
if (4 < x <= 17) and (4 < y <= 17):
continue
orientation = int(1 + 2 * ((x + y) % 2))
for coll in square(x, y, orientation):
ax.add_collection(coll)
for x in range(7, 16):
for y in range(7, 16):
orientation = int(2 + 2 * ((x + y) % 2))
for coll in square(x, y, orientation):
ax.add_collection(coll)
fig.set_facecolor('#AAAAAA')
ax.axis('equal')
ax.axis('off')
ax.axis('tight');