cuGraph

cuGraph is a GPU-accelerated graph library that leverages the Nvidia RAPIDS ecosystem. PyGraphistry provides a more fluent interface to enrich and transform your data with cuGraph methods without the boilerplate.

graphistry.plugins.cugraph.compute_cugraph(self, alg, out_col=None, params={}, kind='Graph', directed=True, G=None)

Run cugraph algorithm on graph. For algorithm parameters, see cuGraph docs.

Parameters
  • alg (str) – algorithm name

  • out_col (Optional[str]) – node table output column name, defaults to alg param

  • params (dict) – algorithm parameters passed to cuGraph as kwargs

  • kind (CuGraphKind) – kind of cugraph to use

  • directed (bool) – whether graph is directed

  • G (Optional[cugraph.Graph]) – cugraph graph to use; if None, use self

  • self (graphistry.Plottable.Plottable) –

Returns

Plottable

Return type

Plottable

Example: Pass params to cugraph
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['c','c','e','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.compute_cugraph('betweenness_centrality', params={'k': 2})
assert 'betweenness_centrality' in g2._nodes.columns
Example: Pagerank
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['c','c','e','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.compute_cugraph('pagerank')
assert 'pagerank' in g2._nodes.columns
Example: Personalized Pagerank
::

edges = pd.DataFrame({‘s’: [‘a’,’b’,’c’,’d’], ‘d’: [‘c’,’c’,’e’,’e’]}) g = graphistry.edges(edges, ‘s’, ‘d’) g2 = g.compute_cugraph(‘pagerank’, params={‘personalization’: cudf.DataFrame({‘vertex’: [‘a’], ‘values’: [1]})}) assert ‘pagerank’ in g2._nodes.columns

Example: Katz centrality with rename
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['c','c','e','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.compute_cugraph('katz_centrality', out_col='katz_centrality_renamed')
assert 'katz_centrality_renamed' in g2._nodes.columns
Parameters
  • self (Plottable) –

  • alg (str) –

  • out_col (Optional[str]) –

  • params (dict) –

  • kind (typing_extensions.Literal[Graph, MultiGraph, BiPartiteGraph]) –

  • G (Optional[Any]) –

Return type

graphistry.Plottable.Plottable

graphistry.plugins.cugraph.df_to_gdf(df)
Parameters

df (Any) –

graphistry.plugins.cugraph.from_cugraph(self, G, node_attributes=None, edge_attributes=None, load_nodes=True, load_edges=True, merge_if_existing=True)

If bound IDs, use the same IDs in the returned graph.

If non-empty nodes/edges, instead of returning G’s topology, use existing topology and merge in G’s attributes

Parameters
  • node_attributes (Optional[List[str]]) –

  • edge_attributes (Optional[List[str]]) –

  • load_nodes (bool) –

  • load_edges (bool) –

  • merge_if_existing (bool) –

Return type

Plottable

graphistry.plugins.cugraph.layout_cugraph(self, layout='force_atlas2', params={}, kind='Graph', directed=True, G=None, bind_position=True, x_out_col='x', y_out_col='y', play=0)

Layout the grpah using a cuGraph algorithm. For a list of layouts, see cugraph documentation (currently just force_atlas2).

Parameters
  • layout (str) – Name of an cugraph layout method like force_atlas2

  • params (dict) – Any named parameters to pass to the underlying cugraph method

  • kind (CuGraphKind) – The kind of cugraph Graph

  • directed (bool) – During the to_cugraph conversion, whether to be directed. (default True)

  • G (Optional[Any]) – The cugraph graph (G) to layout. If None, the current graph is used.

  • bind_position (bool) – Whether to call bind(point_x=, point_y=) (default True)

  • x_out_col (str) – Attribute to write x position to. (default ‘x’)

  • y_out_col (str) – Attribute to write x position to. (default ‘y’)

  • play (Optional[str]) – If defined, set settings(url_params={‘play’: play}). (default 0)

  • self (graphistry.Plottable.Plottable) –

Returns

Plotter

Return type

Plotter

Example: ForceAtlas2 layout
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g.layout_cugraph().plot()
Example: Change which column names are generated
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.layout_cugraph('force_atlas2', x_out_col='my_x', y_out_col='my_y')
assert 'my_x' in g2._nodes
assert g2._point_x == 'my_x'
g2.plot()
Example: Pass parameters to layout methods
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.layout_cugraph('forceatlas_2', params={'lin_log_mode': True, 'prevent_overlapping': True})
g2.plot()
Parameters
  • self (Plottable) –

  • layout (str) –

  • params (dict) –

  • kind (typing_extensions.Literal[Graph, MultiGraph, BiPartiteGraph]) –

  • G (Optional[Any]) –

  • bind_position (bool) –

  • x_out_col (str) –

  • y_out_col (str) –

  • play (Optional[int]) –

Return type

graphistry.Plottable.Plottable

graphistry.plugins.cugraph.to_cugraph(self, directed=True, include_nodes=True, node_attributes=None, edge_attributes=None, kind='Graph')

Convert current graph to a cugraph.Graph object

To assign an edge weight, use g.bind(edge_weight=’some_col’).to_cugraph()

Load from pandas, cudf, or dask_cudf DataFrames

Parameters
  • self (Plottable) –

  • directed (bool) –

  • include_nodes (bool) –

  • node_attributes (Optional[List[str]]) –

  • edge_attributes (Optional[List[str]]) –

  • kind (Literal[‘Graph’, ‘MultiGraph’, ‘BiPartiteGraph’]) –

Constants

graphistry.plugins.cugraph.compute_algs: List[str] = ['betweenness_centrality', 'katz_centrality', 'ecg', 'leiden', 'louvain', 'spectralBalancedCutClustering', 'spectralModularityMaximizationClustering', 'connected_components', 'strongly_connected_components', 'core_number', 'hits', 'pagerank', 'bfs', 'bfs_edges', 'sssp', 'shortest_path', 'shortest_path_length', 'batched_ego_graphs', 'edge_betweenness_centrality', 'jaccard', 'jaccard_w', 'overlap', 'overlap_coefficient', 'overlap_w', 'sorensen', 'sorensen_coefficient', 'sorensen_w', 'ego_graph', 'k_core', 'minimum_spanning_tree']

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.cugraph.layout_algs: List[str] = ['force_atlas2']

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.cugraph_types.CuGraphKind

alias of typing_extensions.Literal[Graph, MultiGraph, BiPartiteGraph]

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.

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

  • directed (bool) –

  • strict (bool) –

  • drop_unsanitary (bool) –

Return type

None

graphistry.plugins.graphviz.g_with_pgv_layout(g, graph)
Parameters
  • g (Plottable) –

  • graph (None) –

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, Any]]) – Graphviz graph attributes, see https://graphviz.org/docs/graph/

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

  • edge_attr (Optional[Dict[graphistry.plugins_types.graphviz_types.EdgeAttr, Any]]) – 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)
Parameters
  • g (Plottable) –

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

  • args (Optional[str]) –

  • directed (bool) –

  • strict (bool) –

  • graph_attr (Optional[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’], Any]]) –

  • node_attr (Optional[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’], Any]]) –

  • edge_attr (Optional[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’], Any]]) –

  • drop_unsanitary (bool) –

Return type

None

graphistry.plugins.graphviz.pgv_styling(g)
Parameters

g (Plottable) –

Return type

Plottable

Constants

graphistry.plugins_types.graphviz_types.EdgeAttr

alias of typing_extensions.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.Format

alias of typing_extensions.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 typing_extensions.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 typing_extensions.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 typing_extensions.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.

igraph

igraph is a popular graph library that PyGraphistry can interface with. This allows you to leverage igraph’s layout algorithms, and optionally, algorithmic enrichments. It is CPU-based and can generally handle small/medium-sized graphs.

graphistry.plugins.igraph.compute_igraph(self, alg, out_col=None, directed=None, use_vids=False, params={}, stringify_rich_types=True)

Enrich or replace graph using igraph methods

Parameters
  • alg (str) – Name of an igraph.Graph method like pagerank

  • out_col (Optional[str]) – For algorithms that generate a node attribute column, out_col is the desired output column name. When None, use the algorithm’s name. (default None)

  • directed (Optional[bool]) – During the to_igraph conversion, whether to be directed. If None, try directed and then undirected. (default None)

  • use_vids (bool) – During the to_igraph conversion, whether to interpret IDs as igraph vertex IDs (non-negative integers) or arbitrary values (False, default)

  • params (dict) – Any named parameters to pass to the underlying igraph method

  • stringify_rich_types (bool) – When rich types like igraph.Graph are returned, which may be problematic for downstream rendering, coerce them to strings

  • self (graphistry.Plottable.Plottable) –

Returns

Plotter

Return type

Plotter

Example: Pagerank
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['c','c','e','e']})
g = graphistry.edges(edges, 's', 'd').materialize_nodes()
g2 = g.compute_igraph('pagerank')
assert 'pagerank' in g2._nodes.columns
Example: Pagerank with custom name
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['c','c','e','e']})
g = graphistry.edges(edges, 's', 'd').materialize_nodes()
g2 = g.compute_igraph('pagerank', out_col='my_pr')
assert 'my_pr' in g2._nodes.columns
Example: Pagerank on an undirected
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['c','c','e','e']})
g = graphistry.edges(edges, 's', 'd').materialize_nodes()
g2 = g.compute_igraph('pagerank', directed=False)
assert 'pagerank' in g2._nodes.columns
Example: Pagerank with custom parameters
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['c','c','e','e']})
g = graphistry.edges(edges, 's', 'd').materialize_nodes()
g2 = g.compute_igraph('pagerank', params={'damping': 0.85})
assert 'pagerank' in g2._nodes.columns
Example: Personalized Pagerank
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['c','c','e','e']})
g = graphistry.edges(edges, 's', 'd').materialize_nodes()
g2 = g.compute_igraph('personalized_pagerank')
assert 'personalized_pagerank' in g2._nodes.columns
Parameters
  • self (Plottable) –

  • alg (str) –

  • out_col (Optional[str]) –

  • directed (Optional[bool]) –

  • params (dict) –

Return type

graphistry.Plottable.Plottable

graphistry.plugins.igraph.from_igraph(self, ig, node_attributes=None, edge_attributes=None, load_nodes=True, load_edges=True, merge_if_existing=True)

Convert igraph object into Plotter

If base g has _node, _source, _destination definitions, use them

When merge_if_existing with preexisting nodes/edges df and shapes match ig, combine attributes

For merge_if_existing to work with edges, must set g._edge and have corresponding edge index attribute in igraph.Graph

Parameters
  • ig (igraph) – Source igraph object

  • node_attributes (Optional[List[str]]) – Subset of node attributes to load; None means all (default)

  • edge_attributes (Optional[List[str]]) – Subset of edge attributes to load; None means all (default)

  • load_nodes (bool) – Whether to load nodes dataframe (default True)

  • load_edges (bool) – Whether to load edges dataframe (default True)

  • merge_if_existing (bool) – Whether to merge with existing node/edge dataframes (default True)

  • merge_if_existing – bool

Return type

Plottable

Returns

Plotter

Example: Convert from igraph, including all node/edge properties
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a', 'b', 'c', 'd'], 'd': ['b', 'c', 'd', 'e'], 'v': [101, 102, 103, 104]})
g = graphistry.edges(edges, 's', 'd').materialize_nodes().get_degrees()
assert 'degree' in g._nodes.columns
g2 = g.from_igraph(g.to_igraph())
assert len(g2._nodes.columns) == len(g._nodes.columns)
Example: Enrich from igraph, but only load in 1 node attribute
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a', 'b', 'c', 'd'], 'd': ['b', 'c', 'd', 'e'], 'v': [101, 102, 103, 104]})
g = graphistry.edges(edges, 's', 'd').materialize_nodes().get_degree()
assert 'degree' in g._nodes
ig = g.to_igraph(include_nodes=False)
assert 'degree' not in ig.vs
ig.vs['pagerank'] = ig.pagerank()
g2 = g.from_igraph(ig, load_edges=False, node_attributes=[g._node, 'pagerank'])
assert 'pagerank' in g2._nodes
asssert 'degree' in g2._nodes
graphistry.plugins.igraph.layout_igraph(self, layout, directed=None, use_vids=False, bind_position=True, x_out_col='x', y_out_col='y', play=0, params={})

Compute graph layout using igraph algorithm. For a list of layouts, see layout_algs or igraph documentation.

Parameters
  • layout (str) – Name of an igraph.Graph.layout method like sugiyama

  • directed (Optional[bool]) – During the to_igraph conversion, whether to be directed. If None, try directed and then undirected. (default None)

  • use_vids (bool) – Whether to use igraph vertex ids (non-negative integers) or arbitary node ids (False, default)

  • bind_position (bool) – Whether to call bind(point_x=, point_y=) (default True)

  • x_out_col (str) – Attribute to write x position to. (default ‘x’)

  • y_out_col (str) – Attribute to write x position to. (default ‘y’)

  • play (Optional[str]) – If defined, set settings(url_params={‘play’: play}). (default 0)

  • params (dict) – Any named parameters to pass to the underlying igraph method

  • self (graphistry.Plottable.Plottable) –

Returns

Plotter

Return type

Plotter

Example: Sugiyama layout
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.layout_igraph('sugiyama')
assert 'x' in g2._nodes
g2.plot()
Example: Change which column names are generated
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.layout_igraph('sugiyama', x_out_col='my_x', y_out_col='my_y')
assert 'my_x' in g2._nodes
assert g2._point_x == 'my_x'
g2.plot()
Example: Pass parameters to layout methods - Sort nodes by degree
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.get_degrees()
assert 'degree' in g._nodes.columns
g3 = g.layout_igraph('sugiyama', params={'layers': 'degree'})
g3.plot()
Parameters
  • self (Plottable) –

  • layout (str) –

  • directed (Optional[bool]) –

  • use_vids (bool) –

  • bind_position (bool) –

  • x_out_col (str) –

  • y_out_col (str) –

  • play (Optional[int]) –

  • params (dict) –

Return type

graphistry.Plottable.Plottable

graphistry.plugins.igraph.to_igraph(self, directed=True, include_nodes=True, node_attributes=None, edge_attributes=None, use_vids=False)

Convert current item to igraph Graph . See examples in from_igraph.

Parameters
  • directed (bool) – Whether to create a directed graph (default True)

  • include_nodes (bool) – Whether to ingest the nodes table, if it exists (default True)

  • node_attributes (Optional[List[str]]) – Which node attributes to load, None means all (default None)

  • edge_attributes (Optional[List[str]]) – Which edge attributes to load, None means all (default None)

  • use_vids (bool) – Whether to interpret IDs as igraph vertex IDs, which must be non-negative integers (default False)

  • self (Plottable) –

Constants

graphistry.plugins.igraph.compute_algs: List[str] = ['articulation_points', 'authority_score', 'betweenness', 'bibcoupling', 'harmonic_centrality', 'closeness', 'clusters', 'cocitation', 'community_edge_betweenness', 'community_fastgreedy', 'community_infomap', 'community_label_propagation', 'community_leading_eigenvector', 'community_leiden', 'community_multilevel', 'community_optimal_modularity', 'community_spinglass', 'community_walktrap', 'constraint', 'coreness', 'gomory_hu_tree', 'harmonic_centrality', 'hub_score', 'eccentricity', 'eigenvector_centrality', 'k_core', 'pagerank', 'personalized_pagerank', 'spanning_tree']

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.igraph.layout_algs: List[str] = ['auto', 'automatic', 'bipartite', 'circle', 'circular', 'dh', 'davidson_harel', 'drl', 'drl_3d', 'fr', 'fruchterman_reingold', 'fr_3d', 'fr3d', 'fruchterman_reingold_3d', 'grid', 'grid_3d', 'graphopt', 'kk', 'kamada_kawai', 'kk_3d', 'kk3d', 'kamada_kawai_3d', 'lgl', 'large', 'large_graph', 'mds', 'random', 'random_3d', 'rt', 'tree', 'reingold_tilford', 'rt_circular', 'reingold_tilford_circular', 'sphere', 'spherical', 'circle_3d', 'circular_3d', 'star', 'sugiyama']

Built-in mutable sequence.

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