Visualize mesa models using python arcade.
Project description
Mesarcade
Mesa + Arcade
Mesarcade is a Python package that provides fast, interactive visualizations of Mesa agent-based models using Python Arcade.
⚠️ Mesarcade is under active development. APIs may change.
Gallery
Schelling
Virus on network
Sugarscape
Components
Mesarcade follows a compositional design: you define how agents are drawn (Artists), where they are drawn (SpacePlots), what is tracked over time (HistoryPlots), and how parameters can be changed (Controllers), all embedded in a Canvas.
Artists
Artists are the visual representations of the entities in a mesa model.
CellArtists: A visual representation formesa.Cellandmesa.Property_Layer.CellAgentArtists: A visual representation for a set ofmesa.CellAgents.ContinuousSpaceAgentArtists: A visual representation for a set ofmesa.ContinuousSpaceAgents.NetworkCellArtists: A visual representation for cells in amesa.Network.NetworkAgentArtists: A visual representation for agents on amesa.Network.
Example:
Let's create a visual representation for our CellAgents. We map the agent attribute type to the colors blue and red.
agents = mesar.CellAgentArtists(
gcolor_attribute="type",
color_map={0: "blue", 1: "red"},
)
SpacePlots
SpacePlots are visual representations of certain space types in Mesa and plot the corresponding Artists at their position.
You can add/layer as many artists as you want to.
GridSpacePlot: Visualizes a grid.ContinuousSpacePlot: Visualizes a continuous space.NetworkPlot: A space in which networks are visualized.
Example:
Let's create a visual representation of a grid and add our agent artists. We could add other artists, too.
grid_space = mesar.GridSpacePlot(artists=[agents])
HistoryPlots
Line plots that plot (multiple) values as a function of the simulated time steps.
-
ModelHistoryPlot: Plots model attributes and data that is collected usingmesa.DataCollectoras a function of the simulated time steps. -
(
AgentHistoryPlot: On the ToDo-List.)
Example
Let's add a ModelHistoryPlot that visualizes the model attribute happy over time:
happy_plot = mesar.ModelHistoryPlot(model_attributes=["happy"], labels=["Happy agents"])
ValueDisplay
Text-based display for showing a single value of a model attribute.
Example
Let's add a ValueDisplay that shows the current value of the model attribute happy:
happy_value = mesar.ValueDisplay(model_attribute="happy", label="Happy agents")
Controllers
Interactive controllers of model attributes and parameters.
NumController: A controller for numeric parameters.CatController: A controller for categorical parameters.
Example
Let's add a controller that determines the value of the model parameter homophily:
homophily = mesar.NumController(
parameter_name="homophily",
parameter_value=0.4,
min_value=0,
max_value=1,
step=0.125,
)
Canvas
The Canvas is the main window in which all components are placed.
Example
canvas = mesar.Canvas(
model_class=Schelling, # the mesa model
plots=[space, happy_plot], # all plots
controllers=[density, minority_pc, homophily, width, height], # all controllers
)
# start the visualization
canvas.show()
Full example
More examples can be found in "/mesarcade/examples".
import mesarcade as mesar
from mesa.examples.basic.schelling.model import Schelling
# artists
agents = mesar.CellAgentArtists(
color_attribute="type",
color_map={0: "blue", 1: "red"},
shape="circle",
)
# space plot
space = mesar.GridSpacePlot(artists=agents)
# line plot
happy_plot = mesar.ModelHistoryPlot(model_attributes=["happy"], labels=["Happy agents"])
# value display
happy_value = mesar.ValueDisplay(model_attribute="happy", label="Happy agents")
# controllers
density = mesar.NumController("density", 0.8, 0.1, 0.9, 0.1)
minority_pc = mesar.NumController("minority_pc", 0.2, 0.0, 1.0, 0.05)
homophily = mesar.NumController("homophily", 0.4, 0.0, 1.0, 0.125)
width = mesar.NumController("width", 100, 10, 200, 10)
height = mesar.NumController("height", 100, 10, 200, 10)
# gui window
canvas = mesar.Canvas(
model_class=Schelling,
plots=[space, happy_plot],
value_displays=[happy_value],
controllers=[density, minority_pc, homophily, width, height],
)
# show gui window
canvas.show()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mesarcade-0.1.0.tar.gz.
File metadata
- Download URL: mesarcade-0.1.0.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
570f2e4b9bc0faff3af16ae3dcde1f748e83981002d66a22784c590ee65de734
|
|
| MD5 |
be5ae42a538c1a68a0a7ade300e833f2
|
|
| BLAKE2b-256 |
88873b9ed840d16fab0299dacb674709987a68e12db08bf390019e0c826d1852
|
Provenance
The following attestation bundles were made for mesarcade-0.1.0.tar.gz:
Publisher:
release.yml on mariuzka/mesarcade
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mesarcade-0.1.0.tar.gz -
Subject digest:
570f2e4b9bc0faff3af16ae3dcde1f748e83981002d66a22784c590ee65de734 - Sigstore transparency entry: 909222065
- Sigstore integration time:
-
Permalink:
mariuzka/mesarcade@63df9e4be4b371602e7ceea1cd79db3c9cf94ff5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mariuzka
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@63df9e4be4b371602e7ceea1cd79db3c9cf94ff5 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file mesarcade-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mesarcade-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
623c2b8d6b9270a5cca84c527f6027ff2d4bfac727de1eb34e0fda38de2dfd49
|
|
| MD5 |
a2646931062c96cde1df6a7f9c129b88
|
|
| BLAKE2b-256 |
5be2dbffbcdb1ed86d6b717c5fa6e92606bc7469043747de05e9827b33eeadbd
|
Provenance
The following attestation bundles were made for mesarcade-0.1.0-py3-none-any.whl:
Publisher:
release.yml on mariuzka/mesarcade
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mesarcade-0.1.0-py3-none-any.whl -
Subject digest:
623c2b8d6b9270a5cca84c527f6027ff2d4bfac727de1eb34e0fda38de2dfd49 - Sigstore transparency entry: 909222067
- Sigstore integration time:
-
Permalink:
mariuzka/mesarcade@63df9e4be4b371602e7ceea1cd79db3c9cf94ff5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mariuzka
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@63df9e4be4b371602e7ceea1cd79db3c9cf94ff5 -
Trigger Event:
workflow_dispatch
-
Statement type: