1
- from mesa .visualization import SolaraViz
1
+ from mesa .visualization import SolaraViz , make_plot_measure , make_space_matplotlib
2
2
from model import BoltzmannWealthModel
3
3
4
4
@@ -24,11 +24,34 @@ def agent_portrayal(agent):
24
24
"height" : 10 ,
25
25
}
26
26
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
27
39
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" ,
33
44
)
34
45
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