Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added conditional checks for empty grid placement #2640

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
21 changes: 13 additions & 8 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
Loading