Skip to content

Commit 1134389

Browse files
committed
sugarscape G1MT: Simplify custom space drawer
1 parent 998ed61 commit 1134389

File tree

1 file changed

+3
-6
lines changed
  • examples/sugarscape_g1mt

1 file changed

+3
-6
lines changed

examples/sugarscape_g1mt/app.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import numpy as np
22
import solara
33
from matplotlib.figure import Figure
4-
from mesa.experimental import JupyterViz
4+
from mesa.experimental import JupyterViz, prepare_matplotlib_space
55
from sugarscape_g1mt.model import SugarscapeG1mt
66
from sugarscape_g1mt.resource_agents import Sugar
77
from sugarscape_g1mt.trader_agents import Trader
88

99

10-
def space_drawer(viz):
10+
@prepare_matplotlib_space
11+
def space_drawer(viz, fig, ax):
1112
def portray(g):
1213
layers = {
1314
"sugar": [[np.nan for j in range(g.height)] for i in range(g.width)],
@@ -29,8 +30,6 @@ def portray(g):
2930
layers["spice"][i][j] = value
3031
return layers
3132

32-
fig = Figure()
33-
ax = fig.subplots()
3433
out = portray(viz.model.grid)
3534
# Sugar
3635
# Important note: imshow by default draws from upper left. You have to
@@ -41,8 +40,6 @@ def portray(g):
4140
ax.imshow(out["spice"], cmap="winter", origin="lower")
4241
# Trader
4342
ax.scatter(**out["trader"])
44-
ax.set_axis_off()
45-
solara.FigureMatplotlib(fig, dependencies=[viz.model, viz.df])
4643

4744

4845
model_params = {

0 commit comments

Comments
 (0)