Skip to content

Commit

Permalink
added conditional checks for empty grid placement
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahil-Chhoker committed Jan 23, 2025
1 parent 13518b2 commit 6eb5ea7
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions mesa/visualization/mpl_space_drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,9 @@ def draw_orthogonal_grid(
s_default = (180 / max(space.width, space.height)) ** 2
arguments = collect_agent_data(space, agent_portrayal, size=s_default)

# plot the agents
_scatter(ax, arguments, **kwargs)
if arguments["loc"].size > 0:
# plot the agents
_scatter(ax, arguments, **kwargs)

# further styling
ax.set_xlim(-0.5, space.width - 0.5)
Expand Down Expand Up @@ -433,10 +434,12 @@ def draw_network(
# this assumes that nodes are identified by an integer
# which is true for default nx graphs but might user changeable
pos = np.asarray(list(pos.values()))
arguments["loc"] = pos[arguments["loc"]]

# plot the agents
_scatter(ax, arguments, **kwargs)
if arguments["loc"].size > 0:
arguments["loc"] = pos[arguments["loc"]]

# plot the agents
_scatter(ax, arguments, **kwargs)

# further styling
ax.set_axis_off()
Expand Down Expand Up @@ -484,8 +487,9 @@ def draw_continuous_space(
s_default = (180 / max(width, height)) ** 2
arguments = collect_agent_data(space, agent_portrayal, size=s_default)

# plot the agents
_scatter(ax, arguments, **kwargs)
if arguments["loc"].size > 0:
# plot the agents
_scatter(ax, arguments, **kwargs)

# further visual styling
border_style = "solid" if not space.torus else (0, (5, 10))
Expand Down Expand Up @@ -544,7 +548,8 @@ def draw_voronoi_grid(
ax.set_xlim(x_min - x_padding, x_max + x_padding)
ax.set_ylim(y_min - y_padding, y_max + y_padding)

_scatter(ax, arguments, **kwargs)
if arguments["loc"].size > 0:
_scatter(ax, arguments, **kwargs)

def setup_voroinoimesh(cells):
patches = []
Expand Down Expand Up @@ -602,4 +607,4 @@ def _scatter(ax: Axes, arguments, **kwargs):
zorder=z_order,
**{k: v[logical] for k, v in arguments.items()},
**kwargs,
)
)

0 comments on commit 6eb5ea7

Please sign in to comment.