diff --git a/examples/hotelling_law/app.py b/examples/hotelling_law/app.py index ec195ede..2ebc63be 100644 --- a/examples/hotelling_law/app.py +++ b/examples/hotelling_law/app.py @@ -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(): @@ -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,