Skip to content

Commit d50b2f6

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

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-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

+13-5
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,23 @@ 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+
116+
return wrapped_drawer
117+
118+
119+
@prepare_matplotlib_space
120+
def make_space(viz, space_fig, space_ax):
111121
if isinstance(viz.model.grid, mesa.space.NetworkGrid):
112122
_draw_network_grid(viz, space_ax)
113123
else:
114124
space_ax.scatter(**viz.portray(viz.model.grid))
115-
space_ax.set_axis_off()
116-
solara.FigureMatplotlib(space_fig, dependencies=[viz.model, viz.df])
117125

118126

119127
def make_plot(viz, measure):

0 commit comments

Comments
 (0)