From a58daadcfedb554238dfd572515e7c2b06fceebf Mon Sep 17 00:00:00 2001 From: Ewout ter Hoeven Date: Mon, 22 Jan 2024 22:31:53 +0100 Subject: [PATCH] solara_viz: Add borders around ContinuousSpace (#1988) * solara_viz: Add grey background and borders * solara_viz: Render axis * solara_viz: Better dash Use a 'loosely dashed' line for torus=True See https://matplotlib.org/stable/gallery/lines_bars_and_markers/linestyles.html * solara_viz: Remove background color --- mesa/experimental/components/matplotlib.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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))