diff --git a/mesa/experimental/components/matplotlib.py b/mesa/experimental/components/matplotlib.py index 7932407247b..d67a0862cc5 100644 --- a/mesa/experimental/components/matplotlib.py +++ b/mesa/experimental/components/matplotlib.py @@ -22,7 +22,6 @@ def SpaceMatplotlib(model, agent_portrayal, dependencies: Optional[list[any]] = _draw_continuous_space(space, space_ax, agent_portrayal) else: _draw_grid(space, space_ax, agent_portrayal) - space_ax.set_axis_off() solara.FigureMatplotlib(space_fig, format="png", dependencies=dependencies) @@ -93,14 +92,23 @@ def portray(space): out["c"] = c return out + # Determine border style based on space.torus + border_style = 'solid' if not space.torus else (0, (5, 10)) + + # Set the border of the plot + for spine in space_ax.spines.values(): + spine.set_linewidth(1.5) + spine.set_color('black') + spine.set_linestyle(border_style) + width = space.x_max - space.x_min x_padding = width / 20 height = space.y_max - space.y_min y_padding = height / 20 space_ax.set_xlim(space.x_min - x_padding, space.x_max + x_padding) space_ax.set_ylim(space.y_min - y_padding, space.y_max + y_padding) - space_ax.scatter(**portray(space)) + # Portray and scatter the agents in the space space_ax.scatter(**portray(space))