In [2]:
%matplotlib inline
# Imports
import numpy
import matplotlib.pyplot as plt
import seaborn; seaborn.set()
In [3]:
# Set the grid and cell parameters
grid_size = 25
num_cells = 10
# Create the space and activate random cells
space = numpy.zeros((grid_size, grid_size))
# Now sample the agents.
for cell_id in range(num_cells):
# Sample random position
row = numpy.random.randint(0, grid_size)
col = numpy.random.randint(0, grid_size)
# "Endow" the cell with the resource by setting its value to 1.
space[row, col] = 1
# Output some info about the agent.
print("Endowing cell ({0}, {1}).".format(row, col))
# Now show the space
plt.figure()
plt.pcolor(space, snap=True)
plt.colorbar()
Out[3]:
In [11]:
# Now show the space
plt.figure()
plt.pcolormesh(space, snap=True, shading='flat', edgecolor='#eeeeee')
plt.colorbar()
# Now highlight a few cells
from matplotlib.patches import Rectangle
# Get current axes
ax = plt.gca()
# Iterate over all cells in the grid
for i in range(grid_size):
for j in range(grid_size):
# In reality, we'd want this to represent something real; let's sample a random number for now.
neighbor_similarity = numpy.random.random()
# Draw the rectangle
ax.add_patch(Rectangle((i, j), 1, 1, fill=False, edgecolor='blue', lw=neighbor_similarity))