-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Enhancement: Allow control of filled markers in Altair backend #2957
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
base: main
Are you sure you want to change the base?
Enhancement: Allow control of filled markers in Altair backend #2957
Conversation
Enable users to specify whether agent markers should be filled or outlined in the Altair visualization backend. This addresses an existing FIXME in the code where markers were hardcoded to be filled. Changes: - Add [filled](cci:1://file://wsl.localhost/Ubuntu/root/mesa/tests/test_backends.py:356:4-359:9) field to [AgentPortrayalStyle](cci:2://file://wsl.localhost/Ubuntu/root/mesa/mesa/visualization/components/portrayal_components.py:18:0-82:66) (defaults to True). - Update [AltairBackend](cci:2://file://wsl.localhost/Ubuntu/root/mesa/mesa/visualization/backends/altair_backend.py:30:0-445:19) to use the [filled](cci:1://file://wsl.localhost/Ubuntu/root/mesa/tests/test_backends.py:356:4-359:9) value from the portrayal. - Add regression test to verify [filled](cci:1://file://wsl.localhost/Ubuntu/root/mesa/tests/test_backends.py:356:4-359:9) attribute collection.
for more information, see https://pre-commit.ci
|
Performance benchmarks:
|
|
Thanks @falloficarus22 for this PR, user control was indeed necessary here, but what's the behavior of these changes on the |
Currently, these changes do not affect the Matplotlib backend; it simply ignores the new filled attribute and continues to render filled markers by default. Do you think any changes are needed? |
As I said, I want both the backends to behave similarly, so if you could also apply the same behavior to the matplotlib agents it would be helpful. |
Okay, I'll work on it |
- Updated [collect_agent_data](cci:1://file://wsl.localhost/Ubuntu/root/mesa/mesa/visualization/mpl_space_drawing.py:51:0-191:15) in [mpl_space_drawing.py](cci:7://file://wsl.localhost/Ubuntu/root/mesa/mesa/visualization/mpl_space_drawing.py:0:0-0:0) to respect the [filled](cci:1://file://wsl.localhost/Ubuntu/root/mesa/tests/test_backends.py:356:4-359:9) attribute from [AgentPortrayalStyle](cci:2://file://wsl.localhost/Ubuntu/root/mesa/mesa/visualization/components/portrayal_components.py:18:0-82:66). - Logic added to set and ensure are set when , producing hollow markers consistent with the Altair backend.
for more information, see https://pre-commit.ci
|
@Sahil-Chhoker review |
|
@falloficarus22 We currently maintain four visualization backends: two legacy ones: |
okay |
Implement [filled](cci:1://file://wsl.localhost/Ubuntu/root/mesa/tests/test_backends.py:358:4-359:47) attribute handling in the newer Matplotlib backend and legacy Altair components. This ensures feature parity across all four visualization backends as requested by reviewers. When is specified in [AgentPortrayalStyle](cci:2://file://wsl.localhost/Ubuntu/root/mesa/mesa/visualization/components/portrayal_components.py:18:0-82:66), markers render with a transparent face color and visible edge colors. This behavior is now consistent across the newer backends and legacy components. Specifically: - Update [MatplotlibBackend](cci:2://file://wsl.localhost/Ubuntu/root/mesa/mesa/visualization/backends/matplotlib_backend.py:34:0-437:28) and legacy Altair logic for markers. - Add unit tests in [test_backends.py](cci:7://file://wsl.localhost/Ubuntu/root/mesa/tests/test_backends.py:0:0-0:0) for Matplotlib collection. - Fix boolean comparison lint errors (E712) for Ruff compliance. - Maintain backward compatibility by defaulting [filled](cci:1://file://wsl.localhost/Ubuntu/root/mesa/tests/test_backends.py:358:4-359:47) to True.
|
@Sahil-Chhoker check now |
Summary
This PR enables users to control whether markers in the Altair and Matplotlib visualization backends (both legacy and new) are "filled" or "outlined" via the AgentPortrayalStyle. This resolves an existing FIXME in the codebase and ensures visual consistency across all Mesa visualization components.
Reference: Closes #2956
Motive
Previously, visualization backends often hardcoded the filled status of markers to
True, which limited customization. Users who wanted outline-only shapes (e.g., empty circles or squares) were unable to achieve this without low-level hacks.This change exposes the filled attribute in AgentPortrayalStyle, giving users direct control over this visual property across all four visualization backends, ensuring feature parity as requested.
Implementation
filled: bool | None = Truefield to the dataclass in mesa/visualization/components/portrayal_components.py. It defaults toTrueto maintain backward compatibility.filled=False, the backends set the marker's face color to"none"(transparent) and ensure the edge color is visible, mimicking a hollow marker."filled"key in deprecated dictionary-based portrayals."none"in Matplotlib.Usage Examples
New Portrayal Style (Hollow Markers):
Portrayal Style with Default (Backward Compatible):
Before


After
Additional Notes