Skip to content

Commit 26624c0

Browse files
authored
update examples to use new SolaraViz API (#193)
1 parent c1e051b commit 26624c0

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

examples/basic/boid_flockers/app.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from boid_flockers.model import BoidFlockers
2-
from mesa.visualization import SolaraViz
2+
from mesa.visualization import SolaraViz, make_space_matplotlib
33

44

55
def boid_draw(agent):
@@ -15,11 +15,12 @@ def boid_draw(agent):
1515
"separation": 2,
1616
}
1717

18+
model = BoidFlockers(100, 100, 100, 5, 10, 2)
19+
1820
page = SolaraViz(
19-
model_class=BoidFlockers,
21+
model,
22+
[make_space_matplotlib(agent_portrayal=boid_draw)],
2023
model_params=model_params,
21-
measures=[],
2224
name="BoidFlockers",
23-
agent_portrayal=boid_draw,
2425
)
2526
page # noqa

examples/basic/virus_on_network/app.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import solara
44
from matplotlib.figure import Figure
55
from matplotlib.ticker import MaxNLocator
6-
from mesa.visualization import SolaraViz, make_text
6+
from mesa.visualization import SolaraViz, make_space_matplotlib
77
from virus_on_network.model import State, VirusOnNetwork, number_infected
88

99

@@ -57,7 +57,7 @@ def make_plot(model):
5757
fig.legend()
5858
# Set integer x axis
5959
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
60-
solara.FigureMatplotlib(fig)
60+
return solara.FigureMatplotlib(fig)
6161

6262

6363
model_params = {
@@ -119,14 +119,17 @@ def make_plot(model):
119119
},
120120
}
121121

122+
SpacePlot = make_space_matplotlib(agent_portrayal)
123+
124+
model1 = VirusOnNetwork()
125+
122126
page = SolaraViz(
123-
VirusOnNetwork,
124-
model_params,
125-
measures=[
127+
model1,
128+
[
129+
SpacePlot,
126130
make_plot,
127-
make_text(get_resistant_susceptible_ratio),
131+
get_resistant_susceptible_ratio,
128132
],
129133
name="Virus Model",
130-
agent_portrayal=agent_portrayal,
131134
)
132135
page # noqa

0 commit comments

Comments
 (0)