I'm trying to generate a grid of squares with a small offset between each and thought I would use my superior matplotlib skills. Unfortunately the output only shows one square, so I suspect that the matplotlib isn't getting the message to plot all the patch objects I am initializing, but despite much trawling of stackoverflow I cannot fix this issue.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib.collections as coll
wid = 1
hei = 1
nrows = 5
ncols = 7
inbetween = 0.1
xx = np.arange(0, ncols, (wid+inbetween))
yy = np.arange(0, nrows, (hei+inbetween))
fig = plt.figure()
ax = plt.subplot(111, aspect='equal')
pat = []
for xi in xx:
for yi in yy:
sq = patches.Rectangle((xi, yi), wid, hei, fill=True)
ax.add_patch(sq)
pc = coll.PatchCollection(pat)
ax.add_collection(pc)
plt.axis('off')
plt.show()
plt.savefig('test.png', dpi=90)
Any ideas as to what is going wrong?