Skip to content

Commit 7eac2eb

Browse files
authored
fix(examples): update for mesa>=3.0 (#273)
* chore: update for mesa>=3.0 * cmt
1 parent 51b34d9 commit 7eac2eb

File tree

4 files changed

+61
-41
lines changed

4 files changed

+61
-41
lines changed

examples/forest_fire/app.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from forest_fire.model import ForestFire
2+
from mesa.visualization import (
3+
SolaraViz,
4+
make_plot_component,
5+
make_space_component,
6+
)
7+
from mesa.visualization.user_param import (
8+
Slider,
9+
)
10+
11+
COLORS = {"Fine": "#00AA00", "On Fire": "#880000", "Burned Out": "#000000"}
12+
13+
14+
def forest_fire_portrayal(tree):
15+
if tree is None:
16+
return
17+
portrayal = {"Shape": "rect", "w": 1, "h": 1, "Filled": "true", "Layer": 0}
18+
(x, y) = (tree.cell.coordinate[i] for i in (0, 1))
19+
portrayal["x"] = x
20+
portrayal["y"] = y
21+
portrayal["color"] = COLORS[tree.condition]
22+
return portrayal
23+
24+
25+
def post_process_space(ax):
26+
ax.set_aspect("equal")
27+
ax.set_xticks([])
28+
ax.set_yticks([])
29+
30+
31+
def post_process_lines(ax):
32+
ax.legend(loc="center left", bbox_to_anchor=(1, 0.9))
33+
34+
35+
space_component = make_space_component(
36+
forest_fire_portrayal,
37+
draw_grid=False,
38+
post_process=post_process_space,
39+
)
40+
lineplot_component = make_plot_component(
41+
COLORS,
42+
post_process=post_process_lines,
43+
)
44+
# TODO: add back in pie chart component
45+
# # no current pie chart equivalent in mesa>=3.0
46+
# pie_chart = mesa.visualization.PieChartModule(
47+
# [{"Label": label, "Color": color} for (label, color) in COLORS.items()]
48+
# )
49+
model = ForestFire()
50+
model_params = {
51+
"height": 100,
52+
"width": 100,
53+
"density": Slider("Tree density", 0.65, 0.01, 1.0, 0.01),
54+
}
55+
page = SolaraViz(
56+
model,
57+
components=[space_component, lineplot_component],
58+
model_params=model_params,
59+
name="Forest Fire",
60+
)

examples/forest_fire/forest_fire/server.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

examples/forest_fire/requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
jupyter
2-
matplotlib
3-
mesa~=2.0
2+
mesa[viz]>=3.0

examples/forest_fire/run.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)