Skip to content

Commit 88a394a

Browse files
committed
solara: Implement decorator to simplify custom space drawer
1 parent 24a1df3 commit 88a394a

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

mesa/experimental/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .jupyter_viz import JupyterViz, make_text # noqa
1+
from .jupyter_viz import JupyterViz, make_text, prepare_matplotlib_space # noqa

mesa/experimental/jupyter_viz.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,22 @@ def _draw_network_grid(viz, space_ax):
105105
)
106106

107107

108-
def make_space(viz):
109-
space_fig = Figure()
110-
space_ax = space_fig.subplots()
108+
def prepare_matplotlib_space(drawer):
109+
def wrapped_drawer(viz):
110+
space_fig = Figure()
111+
space_ax = space_fig.subplots()
112+
drawer(viz, space_fig, space_ax)
113+
space_ax.set_axis_off()
114+
solara.FigureMatplotlib(space_fig, dependencies=[viz.model, viz.df])
115+
return wrapped_drawer
116+
117+
118+
@prepare_matplotlib_space
119+
def make_space(viz, space_fig, space_ax):
111120
if isinstance(viz.model.grid, mesa.space.NetworkGrid):
112121
_draw_network_grid(viz, space_ax)
113122
else:
114123
space_ax.scatter(**viz.portray(viz.model.grid))
115-
space_ax.set_axis_off()
116-
solara.FigureMatplotlib(space_fig, dependencies=[viz.model, viz.df])
117124

118125

119126
def make_plot(viz, measure):

0 commit comments

Comments
 (0)