From 7d5ad8abac19163581370663e50811c40105b7c0 Mon Sep 17 00:00:00 2001 From: Sahil Chhoker Date: Wed, 28 May 2025 09:19:57 +0530 Subject: [PATCH 1/2] bug fixes for portrayal components --- mesa/visualization/mpl_space_drawing.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/mesa/visualization/mpl_space_drawing.py b/mesa/visualization/mpl_space_drawing.py index ffd2144dfa5..d593221a4a3 100644 --- a/mesa/visualization/mpl_space_drawing.py +++ b/mesa/visualization/mpl_space_drawing.py @@ -66,8 +66,8 @@ def get_agent_pos(agent, space): elif isinstance(space, Network): agent_x, agent_y = agent.cell.coordinate, agent.cell.coordinate else: - agent_x = agent.pos[0] if agent.pos else agent.cell.coordinate[0] - agent_y = agent.pos[1] if agent.pos else agent.cell.coordinate[1] + agent_x = agent.pos[0] if agent.pos is not None else agent.cell.coordinate[0] + agent_y = agent.pos[1] if agent.pos is not None else agent.cell.coordinate[1] return agent_x, agent_y arguments = { @@ -104,14 +104,12 @@ def get_agent_pos(agent, space): agent_x, agent_y = get_agent_pos(agent, space) # Extract values from the dict, using defaults if not provided - size_val = dict_data.pop("s", style_fields.get("size")) - color_val = dict_data.pop("c", style_fields.get("color")) + size_val = dict_data.pop("size", style_fields.get("size")) + color_val = dict_data.pop("color", style_fields.get("color")) marker_val = dict_data.pop("marker", style_fields.get("marker")) zorder_val = dict_data.pop("zorder", style_fields.get("zorder")) alpha_val = dict_data.pop("alpha", style_fields.get("alpha")) - edgecolors_val = dict_data.pop( - "edgecolors", color_val - ) # default to agent's color if not provided + edgecolors_val = dict_data.pop("edgecolors", None) linewidths_val = dict_data.pop("linewidths", style_fields.get("linewidths")) aps = AgentPortrayalStyle( @@ -158,7 +156,8 @@ def get_agent_pos(agent, space): arguments["marker"].append(aps.marker) arguments["zorder"].append(aps.zorder) arguments["alpha"].append(aps.alpha) - arguments["edgecolors"].append(aps.edgecolors) + if aps.edgecolors is not None: + arguments["edgecolors"].append(aps.edgecolors) arguments["linewidths"].append(aps.linewidths) data = { @@ -756,6 +755,10 @@ def _scatter(ax: Axes, arguments, **kwargs): zorder_mask = z_order == zorder logical = mark_mask & zorder_mask + # No agents with this marker and z-order, skip + if not np.any(logical): + continue + ax.scatter( x[logical], y[logical], From 763b8d5a13e0d9f2ff5338ebf91df05271e16be4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 28 May 2025 03:54:41 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mesa/visualization/mpl_space_drawing.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mesa/visualization/mpl_space_drawing.py b/mesa/visualization/mpl_space_drawing.py index d593221a4a3..52d62ff5e93 100644 --- a/mesa/visualization/mpl_space_drawing.py +++ b/mesa/visualization/mpl_space_drawing.py @@ -66,8 +66,12 @@ def get_agent_pos(agent, space): elif isinstance(space, Network): agent_x, agent_y = agent.cell.coordinate, agent.cell.coordinate else: - agent_x = agent.pos[0] if agent.pos is not None else agent.cell.coordinate[0] - agent_y = agent.pos[1] if agent.pos is not None else agent.cell.coordinate[1] + agent_x = ( + agent.pos[0] if agent.pos is not None else agent.cell.coordinate[0] + ) + agent_y = ( + agent.pos[1] if agent.pos is not None else agent.cell.coordinate[1] + ) return agent_x, agent_y arguments = { @@ -758,7 +762,7 @@ def _scatter(ax: Axes, arguments, **kwargs): # No agents with this marker and z-order, skip if not np.any(logical): continue - + ax.scatter( x[logical], y[logical],