Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sugarscape G1MT: Simplify custom space drawer [DONOTMERGE] #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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