Skip to content
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

Visualisation: Allow different shapes agent portrayals #2164

Closed
EwoutH opened this issue Jul 3, 2024 · 3 comments · Fixed by #2430
Closed

Visualisation: Allow different shapes agent portrayals #2164

EwoutH opened this issue Jul 3, 2024 · 3 comments · Fixed by #2430
Milestone

Comments

@EwoutH
Copy link
Member

EwoutH commented Jul 3, 2024

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:

has_color = "color" in all_agent_data[0]
if has_color:
encoding_dict["color"] = alt.Color("color", type="nominal")
has_size = "size" in all_agent_data[0]
if has_size:
encoding_dict["size"] = alt.Size("size", type="quantitative")

and maybe also in:
for agent in content:
data = agent_portrayal(agent)
x.append(i)
y.append(j)
if "size" in data:
s.append(data["size"])
if "color" in data:
c.append(data["color"])

@EwoutH
Copy link
Member Author

EwoutH commented Jul 3, 2024

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

@Aryan1Mahahjan
Copy link

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
Copy link
Member Author

EwoutH commented Jul 5, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants