Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mesa/experimental/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .jupyter_viz import JupyterViz, make_text # noqa
from .jupyter_viz import JupyterViz, make_text, prepare_matplotlib_space # noqa
18 changes: 13 additions & 5 deletions mesa/experimental/jupyter_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,19 @@ def change_handler(value, name=name):
raise ValueError(f"{input_type} is not a supported input type")


def make_space(model, agent_portrayal):
def prepare_matplotlib_space(drawer):
def wrapped_drawer(model, agent_portrayal):
space_fig = Figure()
space_ax = space_fig.subplots()
drawer(model, agent_portrayal, space_fig, space_ax)
space_ax.set_axis_off()
solara.FigureMatplotlib(space_fig)

return wrapped_drawer


@prepare_matplotlib_space
def make_space(model, agent_portrayal, space_fig, space_ax):
def portray(g):
x = []
y = []
Expand Down Expand Up @@ -248,14 +260,10 @@ def portray(g):
out["c"] = c
return out

space_fig = Figure()
space_ax = space_fig.subplots()
if isinstance(model.grid, mesa.space.NetworkGrid):
_draw_network_grid(model, space_ax, agent_portrayal)
else:
space_ax.scatter(**portray(model.grid))
space_ax.set_axis_off()
solara.FigureMatplotlib(space_fig)


def _draw_network_grid(model, space_ax, agent_portrayal):
Expand Down