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

update boltzmann-wealth update to use new solaraviz api #195

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Changes from 1 commit
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
35 changes: 29 additions & 6 deletions examples/boltzmann_wealth_model_experimental/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mesa.visualization import SolaraViz
from mesa.visualization import SolaraViz, make_plot_measure, make_space_matplotlib
from model import BoltzmannWealthModel


Expand All @@ -24,11 +24,34 @@ def agent_portrayal(agent):
"height": 10,
}

# Create initial model instance
model1 = BoltzmannWealthModel(50, 10, 10)

# Create visualization elements
SpaceGraph = make_space_matplotlib(agent_portrayal)
GiniPlot = make_plot_measure("Gini")

# Create the SolaraViz page. This will automatically create a server and display the
# visualization elements in a web browser.
# Display it using the following command in the example directory:
# solara run app.py
# It will automatically update and display any changes made to this file
page = SolaraViz(
BoltzmannWealthModel,
model_params,
measures=["Gini"],
name="Money Model",
agent_portrayal=agent_portrayal,
model1,
components=[SpaceGraph, GiniPlot],
model_params=model_params,
name="Boltzmann Wealth Model",
)
page # noqa


# In a notebook environment, we can also display the visualization elements directly
# SpaceGraph(model1)
# GiniPlot(model1)

# The plots will be static. If you want to pick up model steps,
# you have to make the model reactive first
# reactive_model = solara.reactive(model1)
# SpaceGraph(reactive_model)
# In a different notebook block:
# reactive_model.value.step()
Loading