Repository navigation
Fix partial network edgecolors in matplotlib visualization - #3712
pragnyanramtha wants to merge 2 commits into
Conversation
|
Performance benchmarks:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes matplotlib network visualization when only some agents provide edgecolors, keeping style arrays aligned for scatter plotting and supporting mixed color specifications.
Changes:
- Always collects an edgecolor slot per agent when any agent specifies edgecolors.
- Fills omitted edgecolors with Matplotlib
"none". - Adds regression coverage for partial edgecolors using string and RGBA tuple values.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
mesa/visualization/mpl_space_drawing.py |
Aligns collected edgecolors with agent data and handles mixed color array conversion. |
mesa/visualization/backends/matplotlib_backend.py |
Applies the same aligned edgecolor collection logic in the backend collector. |
tests/visualization/test_components_matplotlib.py |
Adds network drawing regression tests for partial edgecolors. |
tests/visualization/test_backends.py |
Adds backend data collection regression tests for partial edgecolors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Performance benchmarks:
|
|
@pragnyanramtha.... apologies for the delay in the review. Thanks for finding this and coming up with a good solution. My only concern is the readability and we seem to be violating the DRY (dont repeat yourself) principle as Mesa has effectively the same code 2X. Would you be able to make a common helper function? Something like.... Then call it ...
I didn't dig too deeply and my knowledge of the visualization library is a bit rusty, so let me know if I am missing any complications with this idea. |
|
@pragnyanramtha Please let us know if you are planning on completing this PR. No worries if not, we will build on your work and complete it. Goal is to have is merged by 25 Sept. |
Hello sir can I start working this looks interesting to me? |
@dietcoke-17 Sure if you would like |
|
superseded by #3856 3856 |
Note
Use this template for bug fixes only. For enhancements/new features, use the feature template and get maintainer approval in an issue/discussion before opening a PR.
Pre-PR Checklist
Summary
Fixes a matplotlib network visualization crash when only some agent portrayals include
edgecolors.Bug / Issue
Fixes #2691.
draw_networkexpects per-agent style arrays to stay aligned. When an agent portrayal omittededgecolors, the collectors skipped that entry, so the edgecolor array could be shorter than the node collection. Mixed string and RGBA tuple edgecolor values also need a one-dimensional object array so Matplotlib can consume them consistently.Implementation
edgecolorsentry per agent whenever any agent supplies edgecolors."none"for agents that omit edgecolors."none".draw_networkandMatplotlibBackend.collect_agent_data.Testing
uv run --extra viz --extra network --with pytest pytest -p no:cacheprovider tests/visualization/test_components_matplotlib.py::test_draw_network_with_partial_edgecolors tests/visualization/test_backends.py::test_matplotlib_backend_collects_partial_edgecolors -q-> 4 passeduv run --extra viz --extra network --with pytest pytest -p no:cacheprovider tests/visualization/test_components_matplotlib.py tests/visualization/test_backends.py -q-> 30 passeduv run --extra viz --extra network --with pytest --with ruff ruff check --no-cache mesa/visualization/mpl_space_drawing.py mesa/visualization/backends/matplotlib_backend.py tests/visualization/test_components_matplotlib.py tests/visualization/test_backends.py-> passedgit diff --check-> passedNo screenshots are attached because the regression was an exception before rendering completed; the automated Matplotlib tests cover the before/after failure mode.
Additional Notes
This is scoped to matplotlib visualization style collection. It does not change public APIs, dependencies, schemas, or CI configuration.