-
Notifications
You must be signed in to change notification settings - Fork 180
update examples to use new solara_viz #193
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
from hotelling_law.agents import ConsumerAgent, StoreAgent | ||
from hotelling_law.model import HotellingModel | ||
from matplotlib.figure import Figure | ||
from mesa.visualization import SolaraViz | ||
from mesa.visualization import SolaraViz, make_plot_measure | ||
|
||
model_params = { | ||
"N_stores": { | ||
|
@@ -108,7 +108,8 @@ def agent_portrayal(agent): | |
return portrayal | ||
|
||
|
||
def space_drawer(model, agent_portrayal): | ||
@solara.component | ||
def SpaceDrawer(model): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is capitalized like a Class. For my own knowlegde, does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't they all just objects? ;) As far as I understood this is mostly a convention. It's best to imagine them as neither a class nor a function but as a solara component (because some custom rules apply) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to clarify, since I have looked it up by now. @solara.component does indeed return a regular ´class` object (with a a defined call function, so you can call it like a function). Usually they should still be written in snake_case for standard Python formatting, but thats where the solara convention takes over |
||
fig = Figure(figsize=(8, 5), dpi=100) | ||
ax = fig.subplots() | ||
|
||
|
@@ -338,20 +339,20 @@ def make_revenue_line_chart(model): | |
return solara.FigureMatplotlib(fig) | ||
|
||
|
||
model1 = HotellingModel(20, 20) | ||
|
||
# Instantiate the SolaraViz component with your model | ||
page = SolaraViz( | ||
model_class=HotellingModel, | ||
model_params=model_params, | ||
measures=[ | ||
model1, | ||
components=[ | ||
SpaceDrawer, | ||
make_price_changes_line_chart, | ||
make_market_share_and_price_chart, | ||
make_market_share_line_chart, | ||
"Price Variance", | ||
make_plot_measure("Price Variance"), | ||
make_revenue_line_chart, | ||
], | ||
name="Hotelling's Law Model", | ||
agent_portrayal=agent_portrayal, | ||
space_drawer=space_drawer, | ||
play_interval=150, | ||
) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.