Skip to content

Commit ce2bc01

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

File tree

1 file changed

+3
-8
lines changed
  • examples/sugarscape_g1mt

1 file changed

+3
-8
lines changed

examples/sugarscape_g1mt/app.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import numpy as np
2-
import solara
3-
from matplotlib.figure import Figure
4-
from mesa.experimental import JupyterViz
2+
from mesa.experimental import JupyterViz, prepare_matplotlib_space
53
from sugarscape_g1mt.model import SugarscapeG1mt
64
from sugarscape_g1mt.resource_agents import Sugar
75
from sugarscape_g1mt.trader_agents import Trader
86

97

10-
def space_drawer(viz):
8+
@prepare_matplotlib_space
9+
def space_drawer(viz, fig, ax):
1110
def portray(g):
1211
layers = {
1312
"sugar": [[np.nan for j in range(g.height)] for i in range(g.width)],
@@ -29,8 +28,6 @@ def portray(g):
2928
layers["spice"][i][j] = value
3029
return layers
3130

32-
fig = Figure()
33-
ax = fig.subplots()
3431
out = portray(viz.model.grid)
3532
# Sugar
3633
# Important note: imshow by default draws from upper left. You have to
@@ -41,8 +38,6 @@ def portray(g):
4138
ax.imshow(out["spice"], cmap="winter", origin="lower")
4239
# Trader
4340
ax.scatter(**out["trader"])
44-
ax.set_axis_off()
45-
solara.FigureMatplotlib(fig, dependencies=[viz.model, viz.df])
4641

4742

4843
model_params = {

0 commit comments

Comments
 (0)