Mesa 3.0.0__py3-none-any.whl → 3.0.0a0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of Mesa might be problematic. Click here for more details.
- mesa/__init__.py +3 -3
- mesa/agent.py +114 -406
- mesa/batchrunner.py +27 -54
- mesa/cookiecutter-mesa/cookiecutter.json +8 -0
- mesa/cookiecutter-mesa/hooks/post_gen_project.py +11 -0
- mesa/cookiecutter-mesa/{{cookiecutter.snake}}/README.md +4 -0
- mesa/cookiecutter-mesa/{{cookiecutter.snake}}/app.pytemplate +27 -0
- mesa/cookiecutter-mesa/{{cookiecutter.snake}}/setup.pytemplate +11 -0
- mesa/cookiecutter-mesa/{{cookiecutter.snake}}/{{cookiecutter.snake}}/model.pytemplate +60 -0
- mesa/datacollection.py +29 -140
- mesa/experimental/__init__.py +1 -11
- mesa/experimental/cell_space/__init__.py +1 -16
- mesa/experimental/cell_space/cell.py +23 -93
- mesa/experimental/cell_space/cell_agent.py +21 -117
- mesa/experimental/cell_space/cell_collection.py +17 -54
- mesa/experimental/cell_space/discrete_space.py +8 -92
- mesa/experimental/cell_space/grid.py +8 -32
- mesa/experimental/cell_space/network.py +7 -12
- mesa/experimental/devs/__init__.py +0 -2
- mesa/experimental/devs/eventlist.py +14 -52
- mesa/experimental/devs/examples/epstein_civil_violence.py +39 -71
- mesa/experimental/devs/examples/wolf_sheep.py +45 -45
- mesa/experimental/devs/simulator.py +15 -55
- mesa/main.py +63 -0
- mesa/model.py +83 -211
- mesa/space.py +149 -215
- mesa/time.py +77 -62
- mesa/{experimental → visualization}/UserParam.py +6 -17
- mesa/visualization/__init__.py +2 -25
- mesa/{experimental → visualization}/components/altair.py +0 -10
- mesa/visualization/components/matplotlib.py +134 -0
- mesa/{experimental/solara_viz.py → visualization/jupyter_viz.py} +110 -65
- {mesa-3.0.0.dist-info → mesa-3.0.0a0.dist-info}/METADATA +13 -65
- mesa-3.0.0a0.dist-info/RECORD +38 -0
- mesa-3.0.0.dist-info/licenses/NOTICE → mesa-3.0.0a0.dist-info/licenses/LICENSE +2 -2
- mesa/examples/README.md +0 -37
- mesa/examples/__init__.py +0 -21
- mesa/examples/advanced/epstein_civil_violence/Epstein Civil Violence.ipynb +0 -116
- mesa/examples/advanced/epstein_civil_violence/Readme.md +0 -34
- mesa/examples/advanced/epstein_civil_violence/__init__.py +0 -0
- mesa/examples/advanced/epstein_civil_violence/agents.py +0 -164
- mesa/examples/advanced/epstein_civil_violence/app.py +0 -73
- mesa/examples/advanced/epstein_civil_violence/model.py +0 -114
- mesa/examples/advanced/pd_grid/Readme.md +0 -43
- mesa/examples/advanced/pd_grid/__init__.py +0 -0
- mesa/examples/advanced/pd_grid/agents.py +0 -50
- mesa/examples/advanced/pd_grid/analysis.ipynb +0 -228
- mesa/examples/advanced/pd_grid/app.py +0 -54
- mesa/examples/advanced/pd_grid/model.py +0 -71
- mesa/examples/advanced/sugarscape_g1mt/Readme.md +0 -64
- mesa/examples/advanced/sugarscape_g1mt/__init__.py +0 -0
- mesa/examples/advanced/sugarscape_g1mt/agents.py +0 -344
- mesa/examples/advanced/sugarscape_g1mt/app.py +0 -62
- mesa/examples/advanced/sugarscape_g1mt/model.py +0 -180
- mesa/examples/advanced/sugarscape_g1mt/sugar-map.txt +0 -50
- mesa/examples/advanced/sugarscape_g1mt/tests.py +0 -69
- mesa/examples/advanced/wolf_sheep/Readme.md +0 -57
- mesa/examples/advanced/wolf_sheep/__init__.py +0 -0
- mesa/examples/advanced/wolf_sheep/agents.py +0 -102
- mesa/examples/advanced/wolf_sheep/app.py +0 -84
- mesa/examples/advanced/wolf_sheep/model.py +0 -137
- mesa/examples/basic/__init__.py +0 -0
- mesa/examples/basic/boid_flockers/Readme.md +0 -22
- mesa/examples/basic/boid_flockers/__init__.py +0 -0
- mesa/examples/basic/boid_flockers/agents.py +0 -71
- mesa/examples/basic/boid_flockers/app.py +0 -58
- mesa/examples/basic/boid_flockers/model.py +0 -69
- mesa/examples/basic/boltzmann_wealth_model/Readme.md +0 -56
- mesa/examples/basic/boltzmann_wealth_model/__init__.py +0 -0
- mesa/examples/basic/boltzmann_wealth_model/agents.py +0 -31
- mesa/examples/basic/boltzmann_wealth_model/app.py +0 -74
- mesa/examples/basic/boltzmann_wealth_model/model.py +0 -43
- mesa/examples/basic/boltzmann_wealth_model/st_app.py +0 -115
- mesa/examples/basic/conways_game_of_life/Readme.md +0 -39
- mesa/examples/basic/conways_game_of_life/__init__.py +0 -0
- mesa/examples/basic/conways_game_of_life/agents.py +0 -47
- mesa/examples/basic/conways_game_of_life/app.py +0 -51
- mesa/examples/basic/conways_game_of_life/model.py +0 -31
- mesa/examples/basic/conways_game_of_life/st_app.py +0 -72
- mesa/examples/basic/schelling/Readme.md +0 -40
- mesa/examples/basic/schelling/__init__.py +0 -0
- mesa/examples/basic/schelling/agents.py +0 -26
- mesa/examples/basic/schelling/analysis.ipynb +0 -205
- mesa/examples/basic/schelling/app.py +0 -42
- mesa/examples/basic/schelling/model.py +0 -59
- mesa/examples/basic/virus_on_network/Readme.md +0 -61
- mesa/examples/basic/virus_on_network/__init__.py +0 -0
- mesa/examples/basic/virus_on_network/agents.py +0 -69
- mesa/examples/basic/virus_on_network/app.py +0 -114
- mesa/examples/basic/virus_on_network/model.py +0 -96
- mesa/experimental/cell_space/voronoi.py +0 -257
- mesa/experimental/components/matplotlib.py +0 -242
- mesa/visualization/components/__init__.py +0 -83
- mesa/visualization/components/altair_components.py +0 -188
- mesa/visualization/components/matplotlib_components.py +0 -175
- mesa/visualization/mpl_space_drawing.py +0 -593
- mesa/visualization/solara_viz.py +0 -458
- mesa/visualization/user_param.py +0 -69
- mesa/visualization/utils.py +0 -9
- mesa-3.0.0.dist-info/RECORD +0 -95
- mesa-3.0.0.dist-info/licenses/LICENSE +0 -202
- /mesa/{examples/advanced → cookiecutter-mesa/{{cookiecutter.snake}}/{{cookiecutter.snake}}}/__init__.py +0 -0
- {mesa-3.0.0.dist-info → mesa-3.0.0a0.dist-info}/WHEEL +0 -0
- {mesa-3.0.0.dist-info → mesa-3.0.0a0.dist-info}/entry_points.txt +0 -0
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
"""Altair based solara components for visualization mesa spaces."""
|
|
2
|
-
|
|
3
|
-
import contextlib
|
|
4
|
-
import warnings
|
|
5
|
-
|
|
6
|
-
import solara
|
|
7
|
-
|
|
8
|
-
with contextlib.suppress(ImportError):
|
|
9
|
-
import altair as alt
|
|
10
|
-
|
|
11
|
-
from mesa.experimental.cell_space import DiscreteSpace, Grid
|
|
12
|
-
from mesa.space import ContinuousSpace, _Grid
|
|
13
|
-
from mesa.visualization.utils import update_counter
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def make_space_altair(*args, **kwargs): # noqa: D103
|
|
17
|
-
warnings.warn(
|
|
18
|
-
"make_space_altair has been renamed to make_altair_space",
|
|
19
|
-
DeprecationWarning,
|
|
20
|
-
stacklevel=2,
|
|
21
|
-
)
|
|
22
|
-
return make_altair_space(*args, **kwargs)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def make_altair_space(
|
|
26
|
-
agent_portrayal, propertylayer_portrayal, post_process, **space_drawing_kwargs
|
|
27
|
-
):
|
|
28
|
-
"""Create an Altair-based space visualization component.
|
|
29
|
-
|
|
30
|
-
Args:
|
|
31
|
-
agent_portrayal: Function to portray agents.
|
|
32
|
-
propertylayer_portrayal: not yet implemented
|
|
33
|
-
post_process :not yet implemented
|
|
34
|
-
space_drawing_kwargs : not yet implemented
|
|
35
|
-
|
|
36
|
-
``agent_portrayal`` is called with an agent and should return a dict. Valid fields in this dict are "color",
|
|
37
|
-
"size", "marker", and "zorder". Other field are ignored and will result in a user warning.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
Returns:
|
|
41
|
-
function: A function that creates a SpaceMatplotlib component
|
|
42
|
-
"""
|
|
43
|
-
if agent_portrayal is None:
|
|
44
|
-
|
|
45
|
-
def agent_portrayal(a):
|
|
46
|
-
return {"id": a.unique_id}
|
|
47
|
-
|
|
48
|
-
def MakeSpaceAltair(model):
|
|
49
|
-
return SpaceAltair(model, agent_portrayal)
|
|
50
|
-
|
|
51
|
-
return MakeSpaceAltair
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
@solara.component
|
|
55
|
-
def SpaceAltair(model, agent_portrayal, dependencies: list[any] | None = None):
|
|
56
|
-
"""Create an Altair-based space visualization component.
|
|
57
|
-
|
|
58
|
-
Returns:
|
|
59
|
-
a solara FigureAltair instance
|
|
60
|
-
"""
|
|
61
|
-
update_counter.get()
|
|
62
|
-
space = getattr(model, "grid", None)
|
|
63
|
-
if space is None:
|
|
64
|
-
# Sometimes the space is defined as model.space instead of model.grid
|
|
65
|
-
space = model.space
|
|
66
|
-
|
|
67
|
-
chart = _draw_grid(space, agent_portrayal)
|
|
68
|
-
solara.FigureAltair(chart)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def _get_agent_data_old__discrete_space(space, agent_portrayal):
|
|
72
|
-
"""Format agent portrayal data for old-style discrete spaces.
|
|
73
|
-
|
|
74
|
-
Args:
|
|
75
|
-
space: the mesa.space._Grid instance
|
|
76
|
-
agent_portrayal: the agent portrayal callable
|
|
77
|
-
|
|
78
|
-
Returns:
|
|
79
|
-
list of dicts
|
|
80
|
-
|
|
81
|
-
"""
|
|
82
|
-
all_agent_data = []
|
|
83
|
-
for content, (x, y) in space.coord_iter():
|
|
84
|
-
if not content:
|
|
85
|
-
continue
|
|
86
|
-
if not hasattr(content, "__iter__"):
|
|
87
|
-
# Is a single grid
|
|
88
|
-
content = [content] # noqa: PLW2901
|
|
89
|
-
for agent in content:
|
|
90
|
-
# use all data from agent portrayal, and add x,y coordinates
|
|
91
|
-
agent_data = agent_portrayal(agent)
|
|
92
|
-
agent_data["x"] = x
|
|
93
|
-
agent_data["y"] = y
|
|
94
|
-
all_agent_data.append(agent_data)
|
|
95
|
-
return all_agent_data
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
def _get_agent_data_new_discrete_space(space: DiscreteSpace, agent_portrayal):
|
|
99
|
-
"""Format agent portrayal data for new-style discrete spaces.
|
|
100
|
-
|
|
101
|
-
Args:
|
|
102
|
-
space: the mesa.experiment.cell_space.Grid instance
|
|
103
|
-
agent_portrayal: the agent portrayal callable
|
|
104
|
-
|
|
105
|
-
Returns:
|
|
106
|
-
list of dicts
|
|
107
|
-
|
|
108
|
-
"""
|
|
109
|
-
all_agent_data = []
|
|
110
|
-
|
|
111
|
-
for cell in space.all_cells:
|
|
112
|
-
for agent in cell.agents:
|
|
113
|
-
agent_data = agent_portrayal(agent)
|
|
114
|
-
agent_data["x"] = cell.coordinate[0]
|
|
115
|
-
agent_data["y"] = cell.coordinate[1]
|
|
116
|
-
all_agent_data.append(agent_data)
|
|
117
|
-
return all_agent_data
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
def _get_agent_data_continuous_space(space: ContinuousSpace, agent_portrayal):
|
|
121
|
-
"""Format agent portrayal data for continuous space.
|
|
122
|
-
|
|
123
|
-
Args:
|
|
124
|
-
space: the ContinuousSpace instance
|
|
125
|
-
agent_portrayal: the agent portrayal callable
|
|
126
|
-
|
|
127
|
-
Returns:
|
|
128
|
-
list of dicts
|
|
129
|
-
"""
|
|
130
|
-
all_agent_data = []
|
|
131
|
-
for agent in space._agent_to_index:
|
|
132
|
-
agent_data = agent_portrayal(agent)
|
|
133
|
-
agent_data["x"] = agent.pos[0]
|
|
134
|
-
agent_data["y"] = agent.pos[1]
|
|
135
|
-
all_agent_data.append(agent_data)
|
|
136
|
-
return all_agent_data
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
def _draw_grid(space, agent_portrayal):
|
|
140
|
-
match space:
|
|
141
|
-
case Grid():
|
|
142
|
-
all_agent_data = _get_agent_data_new_discrete_space(space, agent_portrayal)
|
|
143
|
-
case _Grid():
|
|
144
|
-
all_agent_data = _get_agent_data_old__discrete_space(space, agent_portrayal)
|
|
145
|
-
case ContinuousSpace():
|
|
146
|
-
all_agent_data = _get_agent_data_continuous_space(space, agent_portrayal)
|
|
147
|
-
case _:
|
|
148
|
-
raise NotImplementedError(
|
|
149
|
-
f"visualizing {type(space)} is currently not supported through altair"
|
|
150
|
-
)
|
|
151
|
-
|
|
152
|
-
invalid_tooltips = ["color", "size", "x", "y"]
|
|
153
|
-
|
|
154
|
-
x_y_type = "ordinal" if not isinstance(space, ContinuousSpace) else "nominal"
|
|
155
|
-
|
|
156
|
-
encoding_dict = {
|
|
157
|
-
# no x-axis label
|
|
158
|
-
"x": alt.X("x", axis=None, type=x_y_type),
|
|
159
|
-
# no y-axis label
|
|
160
|
-
"y": alt.Y("y", axis=None, type=x_y_type),
|
|
161
|
-
"tooltip": [
|
|
162
|
-
alt.Tooltip(key, type=alt.utils.infer_vegalite_type([value]))
|
|
163
|
-
for key, value in all_agent_data[0].items()
|
|
164
|
-
if key not in invalid_tooltips
|
|
165
|
-
],
|
|
166
|
-
}
|
|
167
|
-
has_color = "color" in all_agent_data[0]
|
|
168
|
-
if has_color:
|
|
169
|
-
encoding_dict["color"] = alt.Color("color", type="nominal")
|
|
170
|
-
has_size = "size" in all_agent_data[0]
|
|
171
|
-
if has_size:
|
|
172
|
-
encoding_dict["size"] = alt.Size("size", type="quantitative")
|
|
173
|
-
|
|
174
|
-
chart = (
|
|
175
|
-
alt.Chart(
|
|
176
|
-
alt.Data(values=all_agent_data), encoding=alt.Encoding(**encoding_dict)
|
|
177
|
-
)
|
|
178
|
-
.mark_point(filled=True)
|
|
179
|
-
.properties(width=280, height=280)
|
|
180
|
-
# .configure_view(strokeOpacity=0) # hide grid/chart lines
|
|
181
|
-
)
|
|
182
|
-
# This is the default value for the marker size, which auto-scales
|
|
183
|
-
# according to the grid area.
|
|
184
|
-
if not has_size:
|
|
185
|
-
length = min(space.width, space.height)
|
|
186
|
-
chart = chart.mark_point(size=30000 / length**2, filled=True)
|
|
187
|
-
|
|
188
|
-
return chart
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"""Matplotlib based solara components for visualization MESA spaces and plots."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import warnings
|
|
6
|
-
from collections.abc import Callable
|
|
7
|
-
|
|
8
|
-
import matplotlib.pyplot as plt
|
|
9
|
-
import solara
|
|
10
|
-
from matplotlib.figure import Figure
|
|
11
|
-
|
|
12
|
-
from mesa.visualization.mpl_space_drawing import draw_space
|
|
13
|
-
from mesa.visualization.utils import update_counter
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def make_space_matplotlib(*args, **kwargs): # noqa: D103
|
|
17
|
-
warnings.warn(
|
|
18
|
-
"make_space_matplotlib has been renamed to make_mpl_space_component",
|
|
19
|
-
DeprecationWarning,
|
|
20
|
-
stacklevel=2,
|
|
21
|
-
)
|
|
22
|
-
return make_mpl_space_component(*args, **kwargs)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def make_mpl_space_component(
|
|
26
|
-
agent_portrayal: Callable | None = None,
|
|
27
|
-
propertylayer_portrayal: dict | None = None,
|
|
28
|
-
post_process: Callable | None = None,
|
|
29
|
-
**space_drawing_kwargs,
|
|
30
|
-
) -> SpaceMatplotlib:
|
|
31
|
-
"""Create a Matplotlib-based space visualization component.
|
|
32
|
-
|
|
33
|
-
Args:
|
|
34
|
-
agent_portrayal: Function to portray agents.
|
|
35
|
-
propertylayer_portrayal: Dictionary of PropertyLayer portrayal specifications
|
|
36
|
-
post_process : a callable that will be called with the Axes instance. Allows for fine tuning plots (e.g., control ticks)
|
|
37
|
-
space_drawing_kwargs : additional keyword arguments to be passed on to the underlying space drawer function. See
|
|
38
|
-
the functions for drawing the various spaces for further details.
|
|
39
|
-
|
|
40
|
-
``agent_portrayal`` is called with an agent and should return a dict. Valid fields in this dict are "color",
|
|
41
|
-
"size", "marker", "zorder", alpha, linewidths, and edgecolors. Other field are ignored and will result in a user warning.
|
|
42
|
-
|
|
43
|
-
Returns:
|
|
44
|
-
function: A function that creates a SpaceMatplotlib component
|
|
45
|
-
"""
|
|
46
|
-
if agent_portrayal is None:
|
|
47
|
-
|
|
48
|
-
def agent_portrayal(a):
|
|
49
|
-
return {}
|
|
50
|
-
|
|
51
|
-
def MakeSpaceMatplotlib(model):
|
|
52
|
-
return SpaceMatplotlib(
|
|
53
|
-
model,
|
|
54
|
-
agent_portrayal,
|
|
55
|
-
propertylayer_portrayal,
|
|
56
|
-
post_process=post_process,
|
|
57
|
-
**space_drawing_kwargs,
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
return MakeSpaceMatplotlib
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
@solara.component
|
|
64
|
-
def SpaceMatplotlib(
|
|
65
|
-
model,
|
|
66
|
-
agent_portrayal,
|
|
67
|
-
propertylayer_portrayal,
|
|
68
|
-
dependencies: list[any] | None = None,
|
|
69
|
-
post_process: Callable | None = None,
|
|
70
|
-
**space_drawing_kwargs,
|
|
71
|
-
):
|
|
72
|
-
"""Create a Matplotlib-based space visualization component."""
|
|
73
|
-
update_counter.get()
|
|
74
|
-
|
|
75
|
-
space = getattr(model, "grid", None)
|
|
76
|
-
if space is None:
|
|
77
|
-
space = getattr(model, "space", None)
|
|
78
|
-
|
|
79
|
-
fig = Figure()
|
|
80
|
-
ax = fig.add_subplot()
|
|
81
|
-
|
|
82
|
-
draw_space(
|
|
83
|
-
space,
|
|
84
|
-
agent_portrayal,
|
|
85
|
-
propertylayer_portrayal=propertylayer_portrayal,
|
|
86
|
-
ax=ax,
|
|
87
|
-
**space_drawing_kwargs,
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
if post_process is not None:
|
|
91
|
-
post_process(ax)
|
|
92
|
-
|
|
93
|
-
solara.FigureMatplotlib(
|
|
94
|
-
fig, format="png", bbox_inches="tight", dependencies=dependencies
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
def make_plot_measure(*args, **kwargs): # noqa: D103
|
|
99
|
-
warnings.warn(
|
|
100
|
-
"make_plot_measure has been renamed to make_plot_component",
|
|
101
|
-
DeprecationWarning,
|
|
102
|
-
stacklevel=2,
|
|
103
|
-
)
|
|
104
|
-
return make_mpl_plot_component(*args, **kwargs)
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
def make_mpl_plot_component(
|
|
108
|
-
measure: str | dict[str, str] | list[str] | tuple[str],
|
|
109
|
-
post_process: Callable | None = None,
|
|
110
|
-
save_format="png",
|
|
111
|
-
):
|
|
112
|
-
"""Create a plotting function for a specified measure.
|
|
113
|
-
|
|
114
|
-
Args:
|
|
115
|
-
measure (str | dict[str, str] | list[str] | tuple[str]): Measure(s) to plot.
|
|
116
|
-
post_process: a user-specified callable to do post-processing called with the Axes instance.
|
|
117
|
-
save_format: save format of figure in solara backend
|
|
118
|
-
|
|
119
|
-
Returns:
|
|
120
|
-
function: A function that creates a PlotMatplotlib component.
|
|
121
|
-
"""
|
|
122
|
-
|
|
123
|
-
def MakePlotMatplotlib(model):
|
|
124
|
-
return PlotMatplotlib(
|
|
125
|
-
model, measure, post_process=post_process, save_format=save_format
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
return MakePlotMatplotlib
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
@solara.component
|
|
132
|
-
def PlotMatplotlib(
|
|
133
|
-
model,
|
|
134
|
-
measure,
|
|
135
|
-
dependencies: list[any] | None = None,
|
|
136
|
-
post_process: Callable | None = None,
|
|
137
|
-
save_format="png",
|
|
138
|
-
):
|
|
139
|
-
"""Create a Matplotlib-based plot for a measure or measures.
|
|
140
|
-
|
|
141
|
-
Args:
|
|
142
|
-
model (mesa.Model): The model instance.
|
|
143
|
-
measure (str | dict[str, str] | list[str] | tuple[str]): Measure(s) to plot.
|
|
144
|
-
dependencies (list[any] | None): Optional dependencies for the plot.
|
|
145
|
-
post_process: a user-specified callable to do post-processing called with the Axes instance.
|
|
146
|
-
save_format: format used for saving the figure.
|
|
147
|
-
|
|
148
|
-
Returns:
|
|
149
|
-
solara.FigureMatplotlib: A component for rendering the plot.
|
|
150
|
-
"""
|
|
151
|
-
update_counter.get()
|
|
152
|
-
fig = Figure()
|
|
153
|
-
ax = fig.subplots()
|
|
154
|
-
df = model.datacollector.get_model_vars_dataframe()
|
|
155
|
-
if isinstance(measure, str):
|
|
156
|
-
ax.plot(df.loc[:, measure])
|
|
157
|
-
ax.set_ylabel(measure)
|
|
158
|
-
elif isinstance(measure, dict):
|
|
159
|
-
for m, color in measure.items():
|
|
160
|
-
ax.plot(df.loc[:, m], label=m, color=color)
|
|
161
|
-
ax.legend(loc="best")
|
|
162
|
-
elif isinstance(measure, list | tuple):
|
|
163
|
-
for m in measure:
|
|
164
|
-
ax.plot(df.loc[:, m], label=m)
|
|
165
|
-
ax.legend(loc="best")
|
|
166
|
-
|
|
167
|
-
if post_process is not None:
|
|
168
|
-
post_process(ax)
|
|
169
|
-
|
|
170
|
-
ax.set_xlabel("Step")
|
|
171
|
-
# Set integer x axis
|
|
172
|
-
ax.xaxis.set_major_locator(plt.MaxNLocator(integer=True))
|
|
173
|
-
solara.FigureMatplotlib(
|
|
174
|
-
fig, format=save_format, bbox_inches="tight", dependencies=dependencies
|
|
175
|
-
)
|