|  | 
| 5 | 5 | from hotelling_law.agents import ConsumerAgent, StoreAgent | 
| 6 | 6 | from hotelling_law.model import HotellingModel | 
| 7 | 7 | from matplotlib.figure import Figure | 
| 8 |  | -from mesa.visualization import SolaraViz | 
|  | 8 | +from mesa.visualization import SolaraViz, make_plot_measure | 
| 9 | 9 | 
 | 
| 10 | 10 | model_params = { | 
| 11 | 11 |     "N_stores": { | 
| @@ -108,7 +108,8 @@ def agent_portrayal(agent): | 
| 108 | 108 |     return portrayal | 
| 109 | 109 | 
 | 
| 110 | 110 | 
 | 
| 111 |  | -def space_drawer(model, agent_portrayal): | 
|  | 111 | +@solara.component | 
|  | 112 | +def SpaceDrawer(model): | 
| 112 | 113 |     fig = Figure(figsize=(8, 5), dpi=100) | 
| 113 | 114 |     ax = fig.subplots() | 
| 114 | 115 | 
 | 
| @@ -338,20 +339,20 @@ def make_revenue_line_chart(model): | 
| 338 | 339 |     return solara.FigureMatplotlib(fig) | 
| 339 | 340 | 
 | 
| 340 | 341 | 
 | 
|  | 342 | +model1 = HotellingModel(20, 20) | 
|  | 343 | + | 
| 341 | 344 | # Instantiate the SolaraViz component with your model | 
| 342 | 345 | page = SolaraViz( | 
| 343 |  | -    model_class=HotellingModel, | 
| 344 |  | -    model_params=model_params, | 
| 345 |  | -    measures=[ | 
|  | 346 | +    model1, | 
|  | 347 | +    components=[ | 
|  | 348 | +        SpaceDrawer, | 
| 346 | 349 |         make_price_changes_line_chart, | 
| 347 | 350 |         make_market_share_and_price_chart, | 
| 348 | 351 |         make_market_share_line_chart, | 
| 349 |  | -        "Price Variance", | 
|  | 352 | +        make_plot_measure("Price Variance"), | 
| 350 | 353 |         make_revenue_line_chart, | 
| 351 | 354 |     ], | 
| 352 | 355 |     name="Hotelling's Law Model", | 
| 353 |  | -    agent_portrayal=agent_portrayal, | 
| 354 |  | -    space_drawer=space_drawer, | 
| 355 | 356 |     play_interval=150, | 
| 356 | 357 | ) | 
| 357 | 358 | 
 | 
|  | 
0 commit comments