Skip to content

Commit d79f74e

Browse files
committed
update boltzmann-wealth update to use new solaraviz api
1 parent 660102f commit d79f74e

File tree

1 file changed

+29
-6
lines changed
  • examples/boltzmann_wealth_model_experimental

1 file changed

+29
-6
lines changed

examples/boltzmann_wealth_model_experimental/app.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from mesa.visualization import SolaraViz
1+
from mesa.visualization import SolaraViz, make_plot_measure, make_space_matplotlib
22
from model import BoltzmannWealthModel
33

44

@@ -24,11 +24,34 @@ def agent_portrayal(agent):
2424
"height": 10,
2525
}
2626

27+
# Create initial model instance
28+
model1 = BoltzmannWealthModel(50, 10, 10)
29+
30+
# Create visualization elements
31+
SpaceGraph = make_space_matplotlib(agent_portrayal)
32+
GiniPlot = make_plot_measure("Gini")
33+
34+
# Create the SolaraViz page. This will automatically create a server and display the
35+
# visualization elements in a web browser.
36+
# Display it using the following command in the example directory:
37+
# solara run app.py
38+
# It will automatically update and display any changes made to this file
2739
page = SolaraViz(
28-
BoltzmannWealthModel,
29-
model_params,
30-
measures=["Gini"],
31-
name="Money Model",
32-
agent_portrayal=agent_portrayal,
40+
model1,
41+
components=[SpaceGraph, GiniPlot],
42+
model_params=model_params,
43+
name="Boltzmann Wealth Model",
3344
)
3445
page # noqa
46+
47+
48+
# In a notebook environment, we can also display the visualization elements directly
49+
# SpaceGraph(model1)
50+
# GiniPlot(model1)
51+
52+
# The plots will be static. If you want to pick up model steps,
53+
# you have to make the model reactive first
54+
# reactive_model = solara.reactive(model1)
55+
# SpaceGraph(reactive_model)
56+
# In a different notebook block:
57+
# reactive_model.value.step()

0 commit comments

Comments
 (0)