@@ -182,7 +182,19 @@ def make_user_input(user_input, name, options):
182
182
raise ValueError (f"{ input_type } is not a supported input type" )
183
183
184
184
185
- def make_space (model , agent_portrayal ):
185
+ def prepare_matplotlib_space (drawer ):
186
+ def wrapped_drawer (model , agent_portrayal ):
187
+ space_fig = Figure ()
188
+ space_ax = space_fig .subplots ()
189
+ drawer (model , agent_portrayal , space_fig , space_ax )
190
+ space_ax .set_axis_off ()
191
+ solara .FigureMatplotlib (space_fig )
192
+
193
+ return wrapped_drawer
194
+
195
+
196
+ @prepare_matplotlib_space
197
+ def make_space (model , agent_portrayal , space_fig , space_ax ):
186
198
def portray (g ):
187
199
x = []
188
200
y = []
@@ -211,14 +223,10 @@ def portray(g):
211
223
out ["c" ] = c
212
224
return out
213
225
214
- space_fig = Figure ()
215
- space_ax = space_fig .subplots ()
216
226
if isinstance (model .grid , mesa .space .NetworkGrid ):
217
227
_draw_network_grid (model , space_ax , agent_portrayal )
218
228
else :
219
229
space_ax .scatter (** portray (model .grid ))
220
- space_ax .set_axis_off ()
221
- solara .FigureMatplotlib (space_fig )
222
230
223
231
224
232
def _draw_network_grid (model , space_ax , agent_portrayal ):
0 commit comments