@@ -182,7 +182,19 @@ def make_user_input(user_input, name, options):
182182        raise  ValueError (f"{ input_type }   is not a supported input type" )
183183
184184
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 ):
186198    def  portray (g ):
187199        x  =  []
188200        y  =  []
@@ -211,14 +223,10 @@ def portray(g):
211223            out ["c" ] =  c 
212224        return  out 
213225
214-     space_fig  =  Figure ()
215-     space_ax  =  space_fig .subplots ()
216226    if  isinstance (model .grid , mesa .space .NetworkGrid ):
217227        _draw_network_grid (model , space_ax , agent_portrayal )
218228    else :
219229        space_ax .scatter (** portray (model .grid ))
220-     space_ax .set_axis_off ()
221-     solara .FigureMatplotlib (space_fig )
222230
223231
224232def  _draw_network_grid (model , space_ax , agent_portrayal ):
0 commit comments