Visualisation: Allow specifying Agent shapes in agent_portrayal#2214
Visualisation: Allow specifying Agent shapes in agent_portrayal#2214
Conversation
"shape" in agent_portrayal corresponds to "marker" in matplotlib's scatter function.
|
Performance benchmarks:
|
|
Implementation LGTM, thank you for implementing this feature. I could test it on the Epstein civil violence model if I have the time. But if you don't mind, showing that the jailed citizens as square in that example would be helpful. You can used the code from mesa/mesa-examples#158 and undo the experimental data collector part. |
Previously, if only some agent_portrayals provided info like size, color, matplotlib would not accept the parameters and the program would crash. Additionally, edited some names for coherence.
|
Performance benchmarks:
|
|
Thanks a lot for this PR! I will review it somewhere tomorrow. |
error message shows public names of visualization attributes. default color and marker fixed to "tab:blue" & "o" respectively
|
@rht could you give a short summary what you already have sufficiently reviewed and what could use a second pair of eyes? |
|
Actually, this PR is already LGTM, and I didn't merge because you still wanted to review. If any, maybe the perf consideration of an array of defaults instead of a single default value scalar, but this is minor because any loop done without calling Matplotlib many times is going to be fast. |
|
Thanks. I would have expected this feature taking less complexity / lines of code, let me take a closer look tomorrow morning. |
|
Okay, I'm largely good with this PR. It's a bit weird matplotlib/matplotlib#11155 was never implemented, but since the only thing changes for our users is that they can now optionally pass a matplotlib shape in a I would like the documentation around this PR to improve a little:
|
Yes, it's optional and is not a breaking change. While it's good to update the docstring now, I think the tutorial change can happen in a separate PR. Otherwise it makes Mesa too bureaucratic to contribute to (that every new feature needs to be in the tutorial in the same PR). |
|
Yeah I see your perspective and also considered that. But otherwise I'm afraid it doesn't get done. Especially with our user base changes need to be (very) visible. @rmhopkins4 let me know if you want to do these things yourself, or otherwise allow us to do it within this PR. |
You should have the ability to edit the PR already, no? |
|
Yes I do, but I don't prefer to edit other peoples PRs without their explicit permission :) |
|
@rmhopkins4 Could you let me know if you want to take up (any of) the remaining points yourself, or if you want us as maintainers to do it? |
|
I can take up the remaining points. If I understand correctly it's just documentation-related. |
|
Perfect, and that’s correct! |
Viz tutorial now mentions that in addition to size and color, default drawer allows for custom shape.
|
Is there a docstring that currently mentions the available options for the |
|
I think you’re right, it’s weird we don’t have that documented. It might have gone lost with the transition from the old to the new visualization. I think this would be the most logical place to add it: |
|
@rmhopkins4 are you done working on it? It looks good! |
@rmhopkins4 I'm ready to merge. Could you add the portrayal code you used to the first PR post? |
|
Congratulations of getting your first PR into Mesa @rmhopkins4! |
|
@rmhopkins4 would you like to update a few example models to use the shapes? If so, this issue includes a list of models already using the new visualization: |


This PR allows specifying an
"shape"in theagent_portrayaldictionary used by matplotlib component of the Solara visualisation. In short, it allows you represent an Agent in any matplotlib marker, by adding a "shape" key-value pair to theagent_portrayaldictionary.This is especially useful when you're using the default shape drawer for grid or continuous space.
For example:
Partial resolution of #2164.
Examples
In Conway's Game of Life life, you can now use black squares for the agents, as how it's traditionally displayed:
You can also conditionally modify the shape, just like you can with the color and size: