projectmesa / mesa

Mesa is an open-source Python library for agent-based modeling, ideal for simulating complex systems and exploring emergent behaviors.
https://mesa.readthedocs.io
Other
2.3k stars 845 forks source link

Visualisation: Allow different shapes agent portrayals #2164

Open EwoutH opened 3 days ago

EwoutH commented 3 days ago

In the old visualisation you could add values like "Shape": "circle" and "Filled": "true" to the agent_portrayal dict.

With the new Solara based visualisation, that's not yet possible. It should be implemented in mesa/visualization/components. Somewhere around here: https://github.com/projectmesa/mesa/blob/74e2df6fdfc2d5172f84eb96469b277b35bfd795/mesa/visualization/components/altair.py#L50-L55 and maybe also in: https://github.com/projectmesa/mesa/blob/74e2df6fdfc2d5172f84eb96469b277b35bfd795/mesa/visualization/components/matplotlib.py#L40-L47

EwoutH commented 3 days ago

In think (in Altair) it's called a Mark: https://altair-viz.github.io/user_guide/marks/index.html

Aryan1Mahahjan commented 2 days ago

Hi, was thinking about using the below, which use the Encode function attribute

has_shape = "shape" in all_agent_data[0]
    if has_shape:
        encoding_dict["shape"] = agent_data["shape"]

has_fill = "fill" in all_agent_data[0]
    if has_shape:
        encoding_dict["fill"] = agent_data["fill"]

The provided code snippet checks for shape and fill keys in agent data. If present, it adds them to the encoding_dict using the corresponding keys shape and fill. This allows you to define visual properties like circle shapes and filled elements for agents in your visualization.

EwoutH commented 1 day ago

Looks like a good start! I think it does need to be passed to Altair or matplotlib later in the code.

Feel free to open a (draft) PR!