graphviz#

graphviz is a popular graph visualization library that PyGraphistry can interface with. This allows you to leverage graphviz’s powerful layout algorithms, and optionally, static picture renderer. It is especially well-known for its “dot” layout algorithm for hierarchical and tree layouts of graphs with less than 10,000 nodes and edges.

For static outputs in notebooks or docs, you can either call graphistry.Plottable.plot_static() (preferred, auto-reuses x/y when present) or graphistry.plugins.graphviz.render_graphviz() for lower-level control.

Auto-display: When called in a Jupyter notebook, plot_static automatically displays the rendered output inline. It returns an SVG or Image object (use .data for raw bytes).

# Simplest form - auto-displays in notebook
g.plot_static()

# Save to file while also displaying
svg_obj = g.plot_static(path='graph.svg')  # saves file AND returns SVG object

plot_static engines:

  • graphviz-svg / graphviz-png (default render image, optional path)

  • graphviz (render to any Graphviz format, e.g., pdf)

  • graphviz-dot (DOT text, optional path)

  • mermaid-code (Mermaid DSL text, optional path)

Styling: Use graph_attr, node_attr, and edge_attr dictionaries:

g.plot_static(
    graph_attr={'rankdir': 'LR', 'bgcolor': 'white'},
    node_attr={'style': 'filled', 'fillcolor': 'lightblue'},
    edge_attr={'color': 'gray'}
)

plot_static() works with any layout source—it will use existing x/y positions if available (reuse_layout=True), or compute layout via graphviz if not.

See the static rendering tutorial for complete examples.

graphistry.plugins.graphviz.g_to_pgv(g, directed=True, strict=False, drop_unsanitary=False, include_positions=False)#
Parameters:
  • g (Plottable)

  • directed (bool)

  • strict (bool)

  • drop_unsanitary (bool)

  • include_positions (bool)

Return type:

AGraph

graphistry.plugins.graphviz.g_with_pgv_layout(g, graph)#
Parameters:
Return type:

Plottable

graphistry.plugins.graphviz.layout_graphviz(self, prog='dot', args=None, directed=True, strict=False, graph_attr=None, node_attr=None, edge_attr=None, skip_styling=False, render_to_disk=False, path=None, format=None, drop_unsanitary=False)#

Use graphviz for layout, such as hierarchical trees and directed acycle graphs

Requires pygraphviz Python bindings and graphviz native libraries to be installed, see https://pygraphviz.github.io/documentation/stable/install.html

See PROGS for available layout algorithms

To render image to disk, set render=True

Parameters:
  • self (Plottable) – Base graph

  • prog (graphistry.plugins_types.graphviz_types.Prog) – Layout algorithm - “dot”, “neato”, …

  • args (Optional[str]) – Additional arguments to pass to the graphviz commandline for layout

  • directed (bool) – Whether the graph is directed (True, default) or undirected (False)

  • strict (bool) – Whether the graph is strict (True) or not (False, default)

  • graph_attr (Optional[Dict[graphistry.plugins_types.graphviz_types.GraphAttr, graphistry.plugins_types.graphviz_types.GraphvizAttrValue]]) – Graphviz graph attributes, see https://graphviz.org/docs/graph/

  • node_attr (Optional[Dict[graphistry.plugins_types.graphviz_types.NodeAttr, graphistry.plugins_types.graphviz_types.GraphvizAttrValue]]) – Graphviz node attributes, see https://graphviz.org/docs/nodes/

  • edge_attr (Optional[Dict[graphistry.plugins_types.graphviz_types.EdgeAttr, graphistry.plugins_types.graphviz_types.GraphvizAttrValue]]) – Graphviz edge attributes, see https://graphviz.org/docs/edges/

  • skip_styling (bool) – Whether to skip applying default styling (False, default) or not (True)

  • render_to_disk (bool) – Whether to render the graph to disk (False, default) or not (True)

  • path (Optional[str]) – Path to save the rendered image when render_to_disk=True

  • format (Optional[graphistry.plugins_types.graphviz_types.Format]) – Format of the rendered image when render_to_disk=True

  • drop_unsanitary (bool) – Whether to drop unsanitary attributes (False, default) or not (True), recommended for sensitive settings

Returns:

Graph with layout and style settings applied, setting x/y

Return type:

Plottable

Example: Dot layout for rigid hierarchical layout of trees and directed acyclic graphs
import graphistry
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g.layout_graphviz('dot').plot()

Example: Neato layout for organic layout of small graphs

import graphistry
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g.layout_graphviz('neato').plot()

Example: Set graphviz attributes at graph level

import graphistry
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g.layout_graphviz(
    prog='dot',
    graph_attr={
        'ratio': 10
    }
).plot()

Example: Save rendered image to disk as a png

import graphistry
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g.layout_graphviz(
    'dot',
    render_to_disk=True,
    path='graph.png',
    format='png'
)

Example: Save rendered image to disk as a png with passthrough of rendering styles

import graphistry
edges = pd.DataFrame({
    's': ['a','b','c','d'],
    'd': ['b','c','d','e'],
    'color': ['red', None, None, 'yellow']
})
nodes = pd.DataFrame({
    'n': ['a','b','c','d','e'],
    'shape': ['circle', 'square', None, 'square', 'circle']
})
g = graphistry.edges(edges, 's', 'd')
g.layout_graphviz(
    'dot',
    render_to_disk=True,
    path='graph.png',
    format='png'
)
graphistry.plugins.graphviz.layout_graphviz_core(g, prog='dot', args=None, directed=True, strict=False, graph_attr=None, node_attr=None, edge_attr=None, drop_unsanitary=False, include_positions=False)#
Parameters:
  • g (Plottable)

  • prog (Literal['acyclic', 'ccomps', 'circo', 'dot', 'fdp', 'gc', 'gvcolor', 'gvpr', 'neato', 'nop', 'osage', 'patchwork', 'sccmap', 'sfdp', 'tred', 'twopi', 'unflatten'])

  • args (str | None)

  • directed (bool)

  • strict (bool)

  • graph_attr (Dict[Literal['_background', 'bb', 'beautify', 'bgcolor', 'center', 'charset', 'class', 'clusterrank', 'colorscheme', 'comment', 'compound', 'concentrate', 'Damping', 'defaultdist', 'dim', 'dimen', 'diredgeconstraints', 'dpi', 'epsilon', 'esep', 'fontcolor', 'fontname', 'fontnames', 'fontpath', 'fontsize', 'forcelabels', 'gradientangle', 'href', 'id', 'imagepath', 'inputscale', 'K', 'label', 'label_scheme', 'labeljust', 'labelloc', 'landscape', 'layerlistsep', 'layers', 'layerselect', 'layersep', 'layout', 'levels', 'levelsgap', 'lheight', 'linelength', 'lp', 'lwidth', 'margin', 'maxiter', 'mclimit', 'mindist', 'mode', 'model', 'newrank', 'nodesep', 'nojustify', 'normalize', 'notranslate', 'nslimit', 'nslimit1', 'oneblock', 'ordering', 'orientation', 'outputorder', 'overlap', 'overlap_scaling', 'overlap_shrink', 'pack', 'packmode', 'pad', 'page', 'pagedir', 'quadtree', 'quantum', 'rankdir', 'ranksep', 'ratio', 'remincross', 'repulsiveforce', 'resolution', 'root', 'rotate', 'rotation', 'scale', 'searchsize', 'sep', 'showboxes', 'size', 'smoothing', 'sortv', 'splines', 'start', 'style', 'stylesheet', 'target', 'TBbalance', 'tooltip', 'truecolor', 'URL', 'viewport', 'voro_margin', 'xdotversion'], str | int | float | bool] | None)

  • node_attr (Dict[Literal['area', 'class', 'color', 'colorscheme', 'comment', 'distortion', 'fillcolor', 'fixedsize', 'fontcolor', 'fontname', 'fontsize', 'gradientangle', 'group', 'height', 'href', 'id', 'image', 'imagepos', 'imagescale', 'label', 'labelloc', 'layer', 'margin', 'nojustify', 'ordering', 'orientation', 'penwidth', 'peripheries', 'pin', 'pos', 'rects', 'regular', 'root', 'samplepoints', 'shape', 'shapefile', 'showboxes', 'sides', 'skew', 'sortv', 'style', 'target', 'tooltip', 'URL', 'vertices', 'width', 'xlabel', 'xlp', 'z'], str | int | float | bool] | None)

  • edge_attr (Dict[Literal['arrowhead', 'arrowsize', 'arrowtail', 'class', 'color', 'colorscheme', 'comment', 'constraint', 'decorate', 'dir', 'edgehref', 'edgetarget', 'edgetooltip', 'edgeURL', 'fillcolor', 'fontcolor', 'fontname', 'fontsize', 'head_lp', 'headclip', 'headhref', 'headlabel', 'headport', 'headtarget', 'headtooltip', 'headURL', 'href', 'id', 'label', 'labelangle', 'labeldistance', 'labelfloat', 'labelfontcolor', 'labelfontname', 'labelfontsize', 'labelhref', 'labeltarget', 'labeltooltip', 'labelURL', 'layer', 'len', 'lhead', 'lp', 'ltail', 'minlen', 'nojustify', 'penwidth', 'pos', 'samehead', 'sametail', 'showboxes', 'style', 'tail_lp', 'tailclip', 'tailhref', 'taillabel', 'tailport', 'tailtarget', 'tailtooltip', 'tailURL', 'target', 'tooltip', 'URL', 'weight', 'xlabel', 'xlp'], str | int | float | bool] | None)

  • drop_unsanitary (bool)

  • include_positions (bool)

Return type:

AGraph

graphistry.plugins.graphviz.pgv_styling(g)#
Parameters:

g (Plottable)

Return type:

Plottable

graphistry.plugins.graphviz.render_graphviz(self, prog='dot', format='svg', args=None, directed=True, strict=False, graph_attr=None, node_attr=None, edge_attr=None, drop_unsanitary=False, max_nodes=None, max_edges=None, path=None, include_positions=False)#

Render a graph to an image via graphviz and return the rendered bytes.

This wraps layout_graphviz_core() to compute positions, then draws with pygraphviz. Optionally enforces caps to keep renders small/deterministic for docs/examples.

When include_positions is True and the plot has bound x/y values, the existing layout is preserved rather than recomputed by Graphviz.

Parameters:
  • self (Plottable) – Base graph

  • prog (graphistry.plugins_types.graphviz_types.Prog) – Layout algorithm

  • format (graphistry.plugins_types.graphviz_types.Format) – Render format

  • directed (bool) – Whether the graph is directed

  • strict (bool) – Whether to treat the graph as strict

  • graph_attr (Optional[Dict[graphistry.plugins_types.graphviz_types.GraphAttr, graphistry.plugins_types.graphviz_types.GraphvizAttrValue]]) – Graph-level attributes

  • node_attr (Optional[Dict[graphistry.plugins_types.graphviz_types.NodeAttr, graphistry.plugins_types.graphviz_types.GraphvizAttrValue]]) – Node-level attributes

  • edge_attr (Optional[Dict[graphistry.plugins_types.graphviz_types.EdgeAttr, graphistry.plugins_types.graphviz_types.GraphvizAttrValue]]) – Edge-level attributes

  • drop_unsanitary (bool) – Reject unsanitary attrs

  • max_nodes (Optional[int]) – Optional cap on nodes for rendering

  • max_edges (Optional[int]) – Optional cap on edges for rendering

  • path (Optional[str]) – Optional path to also write the render

  • args (str | None)

  • include_positions (bool)

Returns:

Rendered bytes (SVG/PNG/etc.)

Return type:

bytes

Constants

graphistry.plugins_types.graphviz_types.EdgeAttr

alias of Literal[‘arrowhead’, ‘arrowsize’, ‘arrowtail’, ‘class’, ‘color’, ‘colorscheme’, ‘comment’, ‘constraint’, ‘decorate’, ‘dir’, ‘edgehref’, ‘edgetarget’, ‘edgetooltip’, ‘edgeURL’, ‘fillcolor’, ‘fontcolor’, ‘fontname’, ‘fontsize’, ‘head_lp’, ‘headclip’, ‘headhref’, ‘headlabel’, ‘headport’, ‘headtarget’, ‘headtooltip’, ‘headURL’, ‘href’, ‘id’, ‘label’, ‘labelangle’, ‘labeldistance’, ‘labelfloat’, ‘labelfontcolor’, ‘labelfontname’, ‘labelfontsize’, ‘labelhref’, ‘labeltarget’, ‘labeltooltip’, ‘labelURL’, ‘layer’, ‘len’, ‘lhead’, ‘lp’, ‘ltail’, ‘minlen’, ‘nojustify’, ‘penwidth’, ‘pos’, ‘samehead’, ‘sametail’, ‘showboxes’, ‘style’, ‘tail_lp’, ‘tailclip’, ‘tailhref’, ‘taillabel’, ‘tailport’, ‘tailtarget’, ‘tailtooltip’, ‘tailURL’, ‘target’, ‘tooltip’, ‘URL’, ‘weight’, ‘xlabel’, ‘xlp’]

graphistry.plugins_types.graphviz_types.GraphvizAttrValue

alias of str | int | float | bool

graphistry.plugins_types.graphviz_types.Format

alias of Literal[‘canon’, ‘cmap’, ‘cmapx’, ‘cmapx_np’, ‘dia’, ‘dot’, ‘fig’, ‘gd’, ‘gd2’, ‘gif’, ‘hpgl’, ‘imap’, ‘imap_np’, ‘ismap’, ‘jpe’, ‘jpeg’, ‘jpg’, ‘mif’, ‘mp’, ‘pcl’, ‘pdf’, ‘pic’, ‘plain’, ‘plain-ext’, ‘png’, ‘ps’, ‘ps2’, ‘svg’, ‘svgz’, ‘vml’, ‘vmlz’, ‘vrml’, ‘vtx’, ‘wbmp’, ‘xdot’, ‘xlib’]

graphistry.plugins_types.graphviz_types.GraphAttr

alias of Literal[‘_background’, ‘bb’, ‘beautify’, ‘bgcolor’, ‘center’, ‘charset’, ‘class’, ‘clusterrank’, ‘colorscheme’, ‘comment’, ‘compound’, ‘concentrate’, ‘Damping’, ‘defaultdist’, ‘dim’, ‘dimen’, ‘diredgeconstraints’, ‘dpi’, ‘epsilon’, ‘esep’, ‘fontcolor’, ‘fontname’, ‘fontnames’, ‘fontpath’, ‘fontsize’, ‘forcelabels’, ‘gradientangle’, ‘href’, ‘id’, ‘imagepath’, ‘inputscale’, ‘K’, ‘label’, ‘label_scheme’, ‘labeljust’, ‘labelloc’, ‘landscape’, ‘layerlistsep’, ‘layers’, ‘layerselect’, ‘layersep’, ‘layout’, ‘levels’, ‘levelsgap’, ‘lheight’, ‘linelength’, ‘lp’, ‘lwidth’, ‘margin’, ‘maxiter’, ‘mclimit’, ‘mindist’, ‘mode’, ‘model’, ‘newrank’, ‘nodesep’, ‘nojustify’, ‘normalize’, ‘notranslate’, ‘nslimit’, ‘nslimit1’, ‘oneblock’, ‘ordering’, ‘orientation’, ‘outputorder’, ‘overlap’, ‘overlap_scaling’, ‘overlap_shrink’, ‘pack’, ‘packmode’, ‘pad’, ‘page’, ‘pagedir’, ‘quadtree’, ‘quantum’, ‘rankdir’, ‘ranksep’, ‘ratio’, ‘remincross’, ‘repulsiveforce’, ‘resolution’, ‘root’, ‘rotate’, ‘rotation’, ‘scale’, ‘searchsize’, ‘sep’, ‘showboxes’, ‘size’, ‘smoothing’, ‘sortv’, ‘splines’, ‘start’, ‘style’, ‘stylesheet’, ‘target’, ‘TBbalance’, ‘tooltip’, ‘truecolor’, ‘URL’, ‘viewport’, ‘voro_margin’, ‘xdotversion’]

graphistry.plugins_types.graphviz_types.NodeAttr

alias of Literal[‘area’, ‘class’, ‘color’, ‘colorscheme’, ‘comment’, ‘distortion’, ‘fillcolor’, ‘fixedsize’, ‘fontcolor’, ‘fontname’, ‘fontsize’, ‘gradientangle’, ‘group’, ‘height’, ‘href’, ‘id’, ‘image’, ‘imagepos’, ‘imagescale’, ‘label’, ‘labelloc’, ‘layer’, ‘margin’, ‘nojustify’, ‘ordering’, ‘orientation’, ‘penwidth’, ‘peripheries’, ‘pin’, ‘pos’, ‘rects’, ‘regular’, ‘root’, ‘samplepoints’, ‘shape’, ‘shapefile’, ‘showboxes’, ‘sides’, ‘skew’, ‘sortv’, ‘style’, ‘target’, ‘tooltip’, ‘URL’, ‘vertices’, ‘width’, ‘xlabel’, ‘xlp’, ‘z’]

graphistry.plugins_types.graphviz_types.Prog

alias of Literal[‘acyclic’, ‘ccomps’, ‘circo’, ‘dot’, ‘fdp’, ‘gc’, ‘gvcolor’, ‘gvpr’, ‘neato’, ‘nop’, ‘osage’, ‘patchwork’, ‘sccmap’, ‘sfdp’, ‘tred’, ‘twopi’, ‘unflatten’]

graphistry.plugins_types.graphviz_types.EDGE_ATTRS typing.List[graphistry.plugins_types.graphviz_types.EdgeAttr]#

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

graphistry.plugins_types.graphviz_types.FORMATS typing.List[graphistry.plugins_types.graphviz_types.Format]#

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

graphistry.plugins_types.graphviz_types.GRAPH_ATTRS typing.List[graphistry.plugins_types.graphviz_types.GraphAttr]#

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

graphistry.plugins_types.graphviz_types.NODE_ATTRS typing.List[graphistry.plugins_types.graphviz_types.NodeAttr]#

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

graphistry.plugins_types.graphviz_types.PROGS typing.List[graphistry.plugins_types.graphviz_types.Prog]#

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.