Quick Guide to PyGraphistry layouts#

This guide provides a quick introduction to key layout concepts in PyGraphistry

Key Concepts Covered#

Key Concepts#

Precomputed Layouts#

Precomputed layouts involve manually calculating node positions (x, y columns) before rendering your graph.

This is useful such as when you need to manually control a layout, or are visualizing externally provided positions such as from embeddings.

# Precomputed 'x', 'y' coordinates in a nodes DataFrame
g = graphistry.edges(e_df, 'src', 'dst').nodes(n_df, 'n')
g2 = g.settings(url_params={'play': 0})  # skip initial loadtime layout
g2.plot()

Precomputed layouts are ideal for handling complex visualizations where precision is key.

Internal & Plugin Layouts#

PyGraphistry includes a growing number of built-in layouts.

These help with several scenarios, including:

  • Faster performance and greater scale

  • Leveraging Graphistry runtime layout features

  • Combining layouts

Graphistry Layouts:

  • Native Force-Directed Layout: PyGraphistry’s default layout automatically arranges the nodes based on their connectivity on page load.

    g = graphistry.edges(e_df, 'src', 'dst').plot()
    

    Additionally, you can compute it ahead of time. Unlike the visualization server’s pageload-time version, the PyGraphistry version uses the cuGraph (GPU) version, including a subset of the performance and quality improvements.

    g.fa2_layout().plot()
    

    For further details, refer to the FA2 API.

  • Ring Layout: Ideal for visualizing sorted, hierarchical, or time-based data.

    g.time_ring_layout('my_timestamp').plot()
    g.categorical_ring_layout('my_type').plot()
    g.continuous_ring_layout('my_score').plot()
    

    For further details, refer to the Ring Layout API (notebook).

  • Modularity Weighted Layout: Weights edges based on modularity.

    # Separate by precomputed modules
    assert 'partition' in g._nodes
    g.modularity_weighted_layout(community_col='partition').plot()
    
    # Separate by automatically computed modules
    g.modularity_weighted_layout(community_alg='louvain', engine='cudf').plot()
    

    Read more in the Modularity Layout API (notebook).

  • Group-in-a-Box Layout: Groups nodes into a grid of clusters.

    Popularized by NodeXL for analyzing large social networks, the PyGraphistry version enables quickly working with larger datasets than possible in other packages

    g.gib_layout().plot()
    

    Learn more in the Group-in-a-Box Layout API (notebook).

Plugin Layouts:

  • cuGraph Plugin (GPU-accelerated force layouts): Ideal for large-scale graphs requiring performance.

    g.cugraph_force_layout().plot()
    

    See the cuGraph Plugin for more details.

  • GraphViz Plugin (Hierarchical layouts): Great for tree-like or hierarchical data.

    g.graphviz_layout(engine='dot').plot()
    

    Find more details in the GraphViz Plugin.

  • iGraph Plugin (Kamada-Kawai, Sugiyama, etc.): Provides classic layout algorithms for a variety of graph types.

    g.igraph_layout('kamada_kawai').plot()
    

    See the iGraph Plugin for more information.

Runtime Dynamic Layouts#

Dynamic layouts allow PyGraphistry to adjust node positions in real-time based on user interactions and graph updates. This provides highly interactive and scalable graph visualizations.

# Run the force-directed layout at viz load time for 5 seconds (5,000 milliseconds)
g = graphistry.edges(e_df, 'src', 'dst')
g.settings(url_params={'play': 5000}).plot()

For details on runtime settings and customization, explore the Layout Settings page.

Further Reading#

Layout in general:

Individaul layouts and plugins: