Skip to content

Commit c1fae84

Browse files
authored
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
1 parent b96db8f commit c1fae84

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

mesa/experimental/components/matplotlib.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def SpaceMatplotlib(model, agent_portrayal, dependencies: Optional[list[any]] =
2222
_draw_continuous_space(space, space_ax, agent_portrayal)
2323
else:
2424
_draw_grid(space, space_ax, agent_portrayal)
25-
space_ax.set_axis_off()
2625
solara.FigureMatplotlib(space_fig, format="png", dependencies=dependencies)
2726

2827

@@ -93,14 +92,23 @@ def portray(space):
9392
out["c"] = c
9493
return out
9594

95+
# Determine border style based on space.torus
96+
border_style = 'solid' if not space.torus else (0, (5, 10))
97+
98+
# Set the border of the plot
99+
for spine in space_ax.spines.values():
100+
spine.set_linewidth(1.5)
101+
spine.set_color('black')
102+
spine.set_linestyle(border_style)
103+
96104
width = space.x_max - space.x_min
97105
x_padding = width / 20
98106
height = space.y_max - space.y_min
99107
y_padding = height / 20
100108
space_ax.set_xlim(space.x_min - x_padding, space.x_max + x_padding)
101109
space_ax.set_ylim(space.y_min - y_padding, space.y_max + y_padding)
102-
space_ax.scatter(**portray(space))
103110

111+
# Portray and scatter the agents in the space
104112
space_ax.scatter(**portray(space))
105113

106114

0 commit comments

Comments
 (0)