Skip to content

Commit

Permalink
solara: Implement decorator to simplify custom space drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
rht committed Aug 21, 2023
1 parent 24a1df3 commit 88a394a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
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
17 changes: 12 additions & 5 deletions mesa/experimental/jupyter_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,22 @@ def _draw_network_grid(viz, space_ax):
)


def make_space(viz):
space_fig = Figure()
space_ax = space_fig.subplots()
def prepare_matplotlib_space(drawer):
def wrapped_drawer(viz):
space_fig = Figure()
space_ax = space_fig.subplots()
drawer(viz, space_fig, space_ax)
space_ax.set_axis_off()
solara.FigureMatplotlib(space_fig, dependencies=[viz.model, viz.df])
return wrapped_drawer


@prepare_matplotlib_space
def make_space(viz, space_fig, space_ax):
if isinstance(viz.model.grid, mesa.space.NetworkGrid):
_draw_network_grid(viz, space_ax)
else:
space_ax.scatter(**viz.portray(viz.model.grid))
space_ax.set_axis_off()
solara.FigureMatplotlib(space_fig, dependencies=[viz.model, viz.df])


def make_plot(viz, measure):
Expand Down

0 comments on commit 88a394a

Please sign in to comment.