Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions examples/hotelling_law/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,20 @@ def SpaceDrawer(model):
jitter_amount = 0.3 # Jitter for visual separation

for agent in model.agents:
if (
not hasattr(agent, "cell")
or agent.cell is None
or agent.cell.coordinate is None
):
continue

pos = agent.cell.coordinate
portrayal = agent_portrayal(agent)

# Track store agents for cell coloring
if isinstance(agent, StoreAgent):
if agent.pos not in cell_store_contents:
cell_store_contents[agent.pos] = []
cell_store_contents[agent.pos].append(portrayal)
if pos not in cell_store_contents:
cell_store_contents[pos] = []
cell_store_contents[pos].append(portrayal)

# Color cells based on store occupancy
for pos, stores in cell_store_contents.items():
Expand All @@ -150,11 +157,21 @@ def SpaceDrawer(model):
)
ax.add_patch(rect)

# Jittered scatter plot for all agents
# Jittered scatter plot for all agents
for agent in model.agents:
if (
not hasattr(agent, "cell")
or agent.cell is None
or agent.cell.coordinate is None
):
continue

portrayal = agent_portrayal(agent)
jitter_x = np.random.uniform(-jitter_amount, jitter_amount) + agent.pos[0] + 0.5
jitter_y = np.random.uniform(-jitter_amount, jitter_amount) + agent.pos[1] + 0.5
pos = agent.cell.coordinate

jitter_x = np.random.uniform(-jitter_amount, jitter_amount) + pos[0] + 0.5
jitter_y = np.random.uniform(-jitter_amount, jitter_amount) + pos[1] + 0.5

ax.scatter(
jitter_x,
Expand Down