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

Add advanced customization options for agent visualization #2341

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

EwoutH
Copy link
Member

@EwoutH EwoutH commented Oct 4, 2024

This PR builds on #2242 by @rmhopkins4.

This allows more visualisation options for agents, by allowing specifying edgecolor, linewidth and alpha in the agent_portrayal.

Implementation

  • Refactored the _get_agent_data function to handle new visualization parameters (edge colors, line widths, alpha).
  • Implemented backward compatibility for old keyword arguments using a translation dictionary.
  • Updated _draw_continuous_space and _draw_voronoi functions to use the new agent data format.
  • Improved code reusability by centralizing agent data retrieval logic.
  • Ensured consistency in visualization across different space types (grid, continuous, Voronoi).

Usage Examples

Users can now specify additional properties in their agent portrayal function. For example, display agents with red fill, black edges, and partial transparency.

agent_portrayal = {
        "shape": "^",
        "color": "red",
        "size": 20,
        "edgecolor": "black",
        "linewidth": 2,
        "alpha": 0.7
    }

image

Another example, dependent on the state of the Agent:

def agent_portrayal(agent):
    return {
        "c": "white" if agent.isAlive else "black",
        "s": 45,
        "marker": "*",
        "edgecolors": "purple",
        "linewidths": 0.5,
        "alpha": 0.5,
    }

image

Additional notes

  • This change maintains backward compatibility with existing agent portrayal implementations.
  • The new visualization options are available for all space types (grid, continuous, Voronoi).
  • Future work could include extending these options to network visualizations and adding more advanced styling capabilities.

@EwoutH EwoutH added the enhancement Release notes label label Oct 4, 2024
@EwoutH EwoutH requested a review from Corvince October 4, 2024 11:28

This comment was marked as off-topic.

@quaquel
Copy link
Member

quaquel commented Oct 4, 2024

I like the API idea a lot. No time to review in detail atm.

- Add support for edgecolors, linewidths, and alpha transparency in agent portrayal
- Implement backward compatibility for old keyword arguments
- Refactor _get_agent_data function to handle new visualization parameters
- Update _draw_continuous_space and _draw_voronoi functions to use new agent data format
- Improve code reusability and consistency across different space types

Co-Authored-By: Robert Hopkins <[email protected]>
@EwoutH
Copy link
Member Author

EwoutH commented Oct 5, 2024

I have to fix a few small things, but API wise it's ready. I rebased the PR on the latest main.

@EwoutH EwoutH mentioned this pull request Oct 5, 2024
8 tasks
Copy link
Contributor

@Corvince Corvince left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I somehow missed this PR. Less code, more options sounds good!

@EwoutH
Copy link
Member Author

EwoutH commented Oct 17, 2024

Thanks!

Only now I completely forgot what small things I still needed to fix 😅.


return out
"""Draw agents in a Voronoi space."""
agent_data = _get_agent_data(space, agent_portrayal)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work. This method is for plotting the experimental Voronoi space.

The _get_agent_data method presupposes an old style space because it does for agents, pos in space.coord_iter():.

Copy link
Member

@quaquel quaquel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my remark about how this changes _draw_voronoi (which is a new style experimental space).

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

Successfully merging this pull request may close these issues.

3 participants