# Generated by pandoc-plot 1.9.1
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(2019)
import math
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import itertools
# Hexagon radius in mm
RADIUS = 4
# Dimensions of the bounding box of the hexagons
WIDTH = math.sqrt(3) * RADIUS
HEIGHT = 2 * RADIUS
mm_to_in = 0.03937008
def draw_hexagon(ax, center, radius, color='w'):
ax.add_patch(
mpatches.RegularPolygon(
xy=center,
numVertices=6,
radius=radius,
facecolor=color,
edgecolor="none",
orientation=0,
fill=True,
)
)
figure, ax = plt.subplots(
1, 1, figsize=(100 * mm_to_in, 100 * mm_to_in), frameon=False
)
# Dimensions of the page in mm
ax.set_xlim([0, 100])
ax.set_ylim([0, 100])
centers=list()
for offset_x, offset_y in [(0, 0), (WIDTH / 2, (3 / 2) * RADIUS)]:
rows = np.arange(start=offset_x, stop=105, step=WIDTH)
columns = np.arange(start=offset_y, stop=105, step=3 * RADIUS)
for x, y in itertools.product(rows, columns):
centers.append((x,y))
colormap = plt.get_cmap('inferno')
for (x,y) in centers:
# radius away from bottom left corner
# proportional to the distance of the top right corner
# i.e. 0 < r < 1
r = math.hypot(x, y) / math.hypot(100, 100)
draw_hexagon(ax, center=(x, y), radius=RADIUS, color=colormap(r))
ax.axis("off")
plt.subplots_adjust(top=1, bottom=0, left=0, right=1)