Skip to content

Commit

Permalink
sugarscape G1MT: Simplify custom space drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
rht committed Aug 21, 2023
1 parent 998ed61 commit ce2bc01
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions examples/sugarscape_g1mt/app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import numpy as np
import solara
from matplotlib.figure import Figure
from mesa.experimental import JupyterViz
from mesa.experimental import JupyterViz, prepare_matplotlib_space
from sugarscape_g1mt.model import SugarscapeG1mt
from sugarscape_g1mt.resource_agents import Sugar
from sugarscape_g1mt.trader_agents import Trader


def space_drawer(viz):
@prepare_matplotlib_space
def space_drawer(viz, fig, ax):
def portray(g):
layers = {
"sugar": [[np.nan for j in range(g.height)] for i in range(g.width)],
Expand All @@ -29,8 +28,6 @@ def portray(g):
layers["spice"][i][j] = value
return layers

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


model_params = {
Expand Down

0 comments on commit ce2bc01

Please sign in to comment.