graphistry.layout.modularity_weighted package

Submodules

Module contents

graphistry.layout.modularity_weighted.modularity_weighted.modularity_weighted_layout(g, community_col=None, community_alg=None, community_params=None, same_community_weight=2.0, cross_community_weight=0.3, edge_influence=2.0, engine=<EngineAbstract.AUTO: 'auto'>)

Compute a modularity-weighted layout, where edges are weighted based on whether they connect nodes in the same community or different communities.

Computes the community if not provided, including with GPU acceleration, using Louvain

Parameters
  • g (Plottable) – input graph

  • community_col (Optional[str]) – column in nodes with community labels

  • community_alg (Optional[str]) – community detection algorithm, e.g., ‘louvain’ or ‘community_multilevel’

  • community_params (Optional[Dict[str, Any]]) – parameters for community detection algorithm

  • same_community_weight (float) – weight for edges connecting nodes in the same community

  • cross_community_weight (float) – weight for edges connecting nodes in different communities

  • edge_influence (float) – influence of edge weights on layout

  • engine (EngineAbstract) – graph engine, e.g., ‘pandas’, ‘cudf’, ‘auto’. CPU uses igraph algorithms, and GPU, cugraph

Return type

Plottable

Returns

graph with layout

Example: Basic

g = g.modularity_weighted_layout()
g.plot()

Example: Use existing community labels

assert 'my_community' in g._nodes.columns
g = g.modularity_weighted_layout(community_col='my_community')
g.plot()

Example: Use GPU-accelerated Louvain algorithm

g = g.modularity_weighted_layout(community_alg='louvain', engine='cudf')
g = g.modularity_weighted_layout(community_alg='community_multilevel', engine='pandas')

Example: Use custom layout settings

g = g.modularity_weighted_layout(
    community_col='community',
    same_community_weight=2.0,
    cross_community_weight=0.3,
    edge_influence=2.0
)
g.plot()