From 518a32c84b5eaba19d25ac0924ff2c593678d927 Mon Sep 17 00:00:00 2001 From: Ewout ter Hoeven Date: Mon, 22 Jan 2024 15:45:05 +0100 Subject: [PATCH 1/4] solara_viz: Add grey background and borders --- mesa/experimental/components/matplotlib.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mesa/experimental/components/matplotlib.py b/mesa/experimental/components/matplotlib.py index 7932407247b..29c47548ef6 100644 --- a/mesa/experimental/components/matplotlib.py +++ b/mesa/experimental/components/matplotlib.py @@ -93,14 +93,26 @@ def portray(space): out["c"] = c return out + # Set light grey background + space_ax.set_facecolor('lightgrey') + + # Determine border style based on space.torus + border_style = 'solid' if not space.torus else 'dotted' + + # 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)) From b79cee43948c78e087e411e84c28590d50c7acc5 Mon Sep 17 00:00:00 2001 From: Ewout ter Hoeven Date: Mon, 22 Jan 2024 16:42:20 +0100 Subject: [PATCH 2/4] solara_viz: Render axis --- mesa/experimental/components/matplotlib.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mesa/experimental/components/matplotlib.py b/mesa/experimental/components/matplotlib.py index 29c47548ef6..20d275c76b7 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) From a487c63cf6d38eb187ba1992c89df747d473ed5a Mon Sep 17 00:00:00 2001 From: Ewout ter Hoeven Date: Mon, 22 Jan 2024 16:47:06 +0100 Subject: [PATCH 3/4] solara_viz: Better dash Use a 'loosely dashed' line for torus=True See https://matplotlib.org/stable/gallery/lines_bars_and_markers/linestyles.html --- mesa/experimental/components/matplotlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesa/experimental/components/matplotlib.py b/mesa/experimental/components/matplotlib.py index 20d275c76b7..3967d5675ff 100644 --- a/mesa/experimental/components/matplotlib.py +++ b/mesa/experimental/components/matplotlib.py @@ -96,7 +96,7 @@ def portray(space): space_ax.set_facecolor('lightgrey') # Determine border style based on space.torus - border_style = 'solid' if not space.torus else 'dotted' + border_style = 'solid' if not space.torus else (0, (5, 10)) # Set the border of the plot for spine in space_ax.spines.values(): From 759584e95af9208674afa01aebf202a1410942af Mon Sep 17 00:00:00 2001 From: Ewout ter Hoeven Date: Mon, 22 Jan 2024 22:10:03 +0100 Subject: [PATCH 4/4] solara_viz: Remove background color --- mesa/experimental/components/matplotlib.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/mesa/experimental/components/matplotlib.py b/mesa/experimental/components/matplotlib.py index 3967d5675ff..d67a0862cc5 100644 --- a/mesa/experimental/components/matplotlib.py +++ b/mesa/experimental/components/matplotlib.py @@ -92,9 +92,6 @@ def portray(space): out["c"] = c return out - # Set light grey background - space_ax.set_facecolor('lightgrey') - # Determine border style based on space.torus border_style = 'solid' if not space.torus else (0, (5, 10))