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

Customize network layout, currently only spring layout #2243

Open
rmhopkins4 opened this issue Aug 23, 2024 · 3 comments
Open

Customize network layout, currently only spring layout #2243

rmhopkins4 opened this issue Aug 23, 2024 · 3 comments

Comments

@rmhopkins4
Copy link
Contributor

Currently, without implementing a custom drawer, networks are always drawn with the spring layout. A way to customize this would be well appreciated, whether it be in the agent_portrayal or in the model itself (which does somewhat violate the separation of model & visualization).

## matplotlib.py

# draws using networkx's matplotlib integration
def _draw_network_grid(space, space_ax, agent_portrayal):
    graph = space.G
    pos = nx.spring_layout(graph, seed=0)
    nx.draw(
        graph,
        ax=space_ax,
        pos=pos,
        **agent_portrayal(graph),
    )
@rht
Copy link
Contributor

rht commented Aug 23, 2024

What if there is an arbitrary kwargs that you can pass to nx.draw, ax.plot, and so on, to expose their full API?

@rht
Copy link
Contributor

rht commented Aug 23, 2024

Oh, the layout has to be initialized separately from nx.draw, so this needs a separate kwarg.

@zjost
Copy link

zjost commented Aug 24, 2024

I got around this by just creating a custom viz: https://github.com/projectmesa/mesa-examples/blob/main/examples/aco_tsp/app.py#L39

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

No branches or pull requests

3 participants