graphistry.plugins package

Subpackages

Submodules

graphistry.plugins.igraph module

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

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)

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

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’) 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’) 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’) 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’) g2 = g.compute_igraph(‘pagerank’, params={‘damping’: 0.85}) assert ‘pagerank’ in g2._nodes.columns

Parameters

self (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

Returns

Plotter

Return type

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, 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)

  • 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

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) –

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

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)

  • self (Plottable) –

Module contents