Static Graph Rendering with plot_static()#

Render graphs as static images (SVG, PNG) for documentation, reports, and presentations.

Key point: plot_static() works with any layout - UMAP, ring, graphviz, or manual positions.

[1]:
import pandas as pd
import graphistry

# Sample graph
edges_df = pd.DataFrame({'src': ['a', 'a', 'b', 'c', 'd'], 'dst': ['b', 'c', 'c', 'd', 'e']})
nodes_df = pd.DataFrame({
    'id': ['a', 'b', 'c', 'd', 'e'],
    'type': ['start', 'middle', 'middle', 'middle', 'end'],
    'label': ['Start', 'Step 1', 'Step 2', 'Step 3', 'End']
})
g = graphistry.edges(edges_df, 'src', 'dst').nodes(nodes_df, 'id')

Basic Usage#

Auto-displays in Jupyter, returns SVG object (use .data for bytes):

[2]:
g.plot_static()
[2]:
../../../_images/demos_demos_databases_apis_graphviz_static_rendering_3_0.svg

Styling with graph_attr, node_attr, edge_attr#

[3]:
g.plot_static(
    graph_attr={'rankdir': 'LR', 'bgcolor': 'white'},
    node_attr={'shape': 'box', 'style': 'rounded,filled', 'fillcolor': 'lightblue'},
    edge_attr={'color': 'gray'}
)
[3]:
../../../_images/demos_demos_databases_apis_graphviz_static_rendering_5_0.svg

Per-Node Styling (Data-Driven)#

Add graphviz attribute columns to your dataframe:

[4]:
nodes_styled = nodes_df.copy()
nodes_styled['fillcolor'] = nodes_styled['type'].map({
    'start': 'lightgreen', 'middle': 'lightblue', 'end': 'lightyellow'
})
nodes_styled['shape'] = 'box'

g_styled = graphistry.edges(edges_df, 'src', 'dst').nodes(nodes_styled, 'id')
g_styled.plot_static(graph_attr={'rankdir': 'LR'}, node_attr={'style': 'filled'})
[4]:
../../../_images/demos_demos_databases_apis_graphviz_static_rendering_7_0.svg

Layout Programs#

Program

Best For

dot

Hierarchies, DAGs

neato

Small undirected graphs

circo

Circular layouts

[5]:
g.plot_static(prog='circo', node_attr={'style': 'filled', 'fillcolor': 'lightblue'})
[5]:
../../../_images/demos_demos_databases_apis_graphviz_static_rendering_9_0.svg

Output Formats#

[6]:
# DOT source text
dot = g.plot_static(engine='graphviz-dot')
print(dot[:200])
digraph "" {
        graph [bb="0,0,115.89,324"];
        node [label="\N"];
        a       [height=0.5,
                id=a,
                label=Start,
                pos="74.946,306",
                width=0.95686];
        b       [height=0.5,
                id=b,
                label="Step 1",
                pos="40.946,234"
[7]:
# Mermaid DSL
mermaid = g.plot_static(engine='mermaid-code')
print(mermaid)
graph LR
    a --> b
    a --> c
    b --> c
    c --> d
    d --> e

Finding More Options#

Discover available attributes:

[8]:
from graphistry.plugins_types.graphviz_types import GRAPH_ATTRS, NODE_ATTRS, EDGE_ATTRS, PROGS
print('Progs:', PROGS[:6])
print('Node attrs (sample):', NODE_ATTRS[:8])
Progs: ['acyclic', 'ccomps', 'circo', 'dot', 'fdp', 'gc']
Node attrs (sample): ['area', 'class', 'color', 'colorscheme', 'comment', 'distortion', 'fillcolor', 'fixedsize']

External references: - Graphviz Attributes - Graphviz Shapes - Graphviz Colors

See Also#