Skip to content

Commit

Permalink
solara_viz: Add borders around ContinuousSpace (#1988)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
EwoutH authored Jan 22, 2024
1 parent b96db8f commit c1fae84
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mesa/experimental/components/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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))


Expand Down

0 comments on commit c1fae84

Please sign in to comment.