graphistry package¶
Submodules¶
graphistry.plotter module¶
-
class
graphistry.plotter.
Plotter
¶ Bases:
future.types.newobject.newobject
Graph plotting class.
Created using
Graphistry.bind()
.Chained calls successively add data and visual encodings, and end with a plot call.
To streamline reuse and replayable notebooks, Plotter manipulations are immutable. Each chained call returns a new instance that derives from the previous one. The old plotter or the new one can then be used to create different graphs.
The class supports convenience methods for mixing calls across Pandas, NetworkX, and IGraph.
-
bind
(source=None, destination=None, node=None, edge_title=None, edge_label=None, edge_color=None, edge_weight=None, point_title=None, point_label=None, point_color=None, point_size=None)¶ Relate data attributes to graph structure and visual representation.
To facilitate reuse and replayable notebooks, the binding call is chainable. Invocation does not effect the old binding: it instead returns a new Plotter instance with the new bindings added to the existing ones. Both the old and new bindings can then be used for different graphs.
Parameters: - source (String.) – Attribute containing an edge’s source ID
- destination (String.) – Attribute containing an edge’s destination ID
- node (String.) – Attribute containing a node’s ID
- edge_title (HtmlString.) – Attribute overriding edge’s minimized label text. By default, the edge source and destination is used.
- edge_label (HtmlString.) – Attribute overriding edge’s expanded label text. By default, scrollable list of attribute/value mappings.
- edge_color (String.) – Attribute overriding edge’s color. See palette definitions for values. Based on Color Brewer.
- edge_weight (String.) – Attribute overriding edge weight. Default is 1. Advanced layout controls will relayout edges based on this value.
- point_title (HtmlString.) – Attribute overriding node’s minimized label text. By default, the node ID is used.
- point_label (HtmlString.) – Attribute overriding node’s expanded label text. By default, scrollable list of attribute/value mappings.
- point_color (Integer.) –
Attribute overriding node’s color. See palette definitions for values. Based on Color Brewer.
- point_size (HtmlString.) – Attribute overriding node’s size. By default, uses the node degree. The visualization will normalize point sizes and adjust dynamically using semantic zoom.
Returns: Plotter.
Return type: Plotter.
- Example: Minimal
import graphistry g = graphistry.bind() g = g.bind(source='src', destination='dst')
- Example: Node colors
import graphistry g = graphistry.bind() g = g.bind(source='src', destination='dst', node='id', point_color='color')
- Example: Chaining
import graphistry g = graphistry.bind(source='src', destination='dst', node='id') g1 = g.bind(point_color='color1', point_size='size1') g.bind(point_color='color1b') g2a = g1.bind(point_color='color2a') g2b = g1.bind(point_color='color2b', point_size='size2b') g3a = g2a.bind(point_size='size3a') g3b = g2b.bind(point_size='size3b')
- In the above Chaining example, all bindings use src/dst/id. Colors and sizes bind to:
g: default/default g1: color1/size1 g2a: color2a/size1 g2b: color2b/size2b g3a: color2a/size3a g3b: color2b/size3b
-
edges
(edges)¶ Specify edge list data and associated edge attribute values.
Parameters: edges – Edges and their attributes. Returns: Plotter. Return type: Plotter. - Example
import graphistry df = pandas.DataFrame({'src': [0,1,2], 'dst': [1,2,0]}) graphistry .bind(source='src', destination='dst') .edges(df) .plot()
-
graph
(ig)¶ Specify the node and edge data.
Parameters: ig (NetworkX graph or an IGraph graph.) – Graph with node and edge attributes. Returns: Plotter. Return type: Plotter.
-
igraph2pandas
(ig)¶ Under current bindings, transform an IGraph into a pandas edges dataframe and a nodes dataframe.
- Example
import graphistry g = graphistry.bind() es = pandas.DataFrame({'src': [0,1,2], 'dst': [1,2,0]}) g = g.bind(source='src', destination='dst').edges(es) ig = g.pandas2igraph(es) ig.vs['community'] = ig.community_infomap().membership (es2, vs2) = g.igraph2pandas(ig) g.nodes(vs2).bind(point_color='community').plot()
-
networkx2pandas
(g)¶
-
nodes
(nodes)¶ Specify the set of nodes and associated data.
Must include any nodes referenced in the edge list.
Parameters: nodes – Nodes and their attributes. Returns: Plotter. Return type: Plotter. - Example
import graphistry es = pandas.DataFrame({'src': [0,1,2], 'dst': [1,2,0]}) g = graphistry .bind(source='src', destination='dst') .edges(es) vs = pandas.DataFrame({'v': [0,1,2], 'lbl': ['a', 'b', 'c']}) g = g.bind(node='v').nodes(vs) g.plot()
-
pandas2igraph
(edges, directed=True)¶ Convert a pandas edge dataframe to an IGraph graph.
Uses current bindings. Defaults to treating edges as directed.
- Example
import graphistry g = graphistry.bind() es = pandas.DataFrame({'src': [0,1,2], 'dst': [1,2,0]}) g = g.bind(source='src', destination='dst') ig = g.pandas2igraph(es) ig.vs['community'] = ig.community_infomap().membership g.bind(point_color='community').plot(ig)
-
plot
(graph=None, nodes=None, name=None)¶ Upload data to the Graphistry server and show as an iframe of it.
name, Uses the currently bound schema structure and visual encodings. Optional parameters override the current bindings.
When used in a notebook environment, will also show an iframe of the visualization.
Parameters: - graph (Pandas dataframe, NetworkX graph, or IGraph graph.) – Edge table or graph.
- nodes (Pandas dataframe.) – Nodes table.
- Example: Simple
import graphistry es = pandas.DataFrame({'src': [0,1,2], 'dst': [1,2,0]}) graphistry .bind(source='src', destination='dst') .edges(es) .plot()
- Example: Shorthand
import graphistry es = pandas.DataFrame({'src': [0,1,2], 'dst': [1,2,0]}) graphistry .bind(source='src', destination='dst') .plot(es)
-
settings
(height=None, url_params={})¶ Specify iframe height and add URL parameter dictionary.
The library takes care of URI component encoding for the dictionary.
Parameters: - height (Integer.) – Height in pixels.
- url_params (Dictionary) – Dictionary of querystring parameters to append to the URL.
-
graphistry.pygraphistry module¶
Top-level import of class PyGraphistry as “Graphistry”. Used to connect to the Graphistry server and then create a base plotter.
-
class
graphistry.pygraphistry.
NumpyJSONEncoder
(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)¶ Bases:
json.encoder.JSONEncoder
-
default
(obj)¶
-
-
class
graphistry.pygraphistry.
PyGraphistry
¶ Bases:
future.types.newobject.newobject
-
static
api_key
(value=None)¶ Set or get the API key. Also set via environment variable GRAPHISTRY_API_KEY.
-
static
api_version
(value=None)¶ Set or get the API version (1 or 2). Also set via environment variable GRAPHISTRY_API_VERSION.
-
static
authenticate
()¶ Authenticate via already provided configuration. This is called once automatically per session when uploading and rendering a visualization.
-
static
bind
(node=None, source=None, destination=None, edge_title=None, edge_label=None, edge_color=None, edge_weight=None, point_title=None, point_label=None, point_color=None, point_size=None)¶ Create a base plotter.
Typically called at start of a program. For parameters, see
plotter.bind()
.Returns: Plotter. Return type: Plotter. Example
import graphistry g = graphistry.bind()
-
static
edges
(edges)¶
-
static
graph
(ig)¶
-
static
nodes
(nodes)¶
-
static
protocol
(value=None)¶ Set or get the protocol (‘http’ or ‘https’). Set automatically when using a server alias. Also set via environment variable GRAPHISTRY_PROTOCOL.
-
static
register
(key=None, server='labs', protocol=None, api=1)¶ API key registration and server selection
Changing the key effects all derived Plotter instances.
Parameters: - key (String.) – API key.
- server (Optional string.) – URL of the visualization server.
- protocol (Optional string.) – Protocol used to contact visualization server
Returns: None.
Return type: None.
- Example: Standard
import graphistry graphistry.register(key="my api key")
- Example: Developer
import graphistry graphistry.register('my api key', server='staging', protocol='https')
- Example: Through environment variable
- ::
- export GRAPHISTRY_API_KEY = ‘my api key’
- ::
- import graphistry graphistry.register()
-
static
server
(value=None)¶ Get the hostname of the server or set the server using hostname or aliases. Supported aliases: ‘localhost’, ‘staging’, ‘labs’. Also set via environment variable GRAPHISTRY_HOSTNAME.
-
static
settings
(height=None, url_params={})¶
-
static
-
graphistry.pygraphistry.
api_key
(value=None)¶ Set or get the API key. Also set via environment variable GRAPHISTRY_API_KEY.
-
graphistry.pygraphistry.
api_version
(value=None)¶ Set or get the API version (1 or 2). Also set via environment variable GRAPHISTRY_API_VERSION.
-
graphistry.pygraphistry.
authenticate
()¶ Authenticate via already provided configuration. This is called once automatically per session when uploading and rendering a visualization.
-
graphistry.pygraphistry.
bind
(node=None, source=None, destination=None, edge_title=None, edge_label=None, edge_color=None, edge_weight=None, point_title=None, point_label=None, point_color=None, point_size=None)¶ Create a base plotter.
Typically called at start of a program. For parameters, see
plotter.bind()
.Returns: Plotter. Return type: Plotter. Example
import graphistry g = graphistry.bind()
-
graphistry.pygraphistry.
edges
(edges)¶
-
graphistry.pygraphistry.
graph
(ig)¶
-
graphistry.pygraphistry.
nodes
(nodes)¶
-
graphistry.pygraphistry.
protocol
(value=None)¶ Set or get the protocol (‘http’ or ‘https’). Set automatically when using a server alias. Also set via environment variable GRAPHISTRY_PROTOCOL.
-
graphistry.pygraphistry.
register
(key=None, server='labs', protocol=None, api=1)¶ API key registration and server selection
Changing the key effects all derived Plotter instances.
Parameters: - key (String.) – API key.
- server (Optional string.) – URL of the visualization server.
- protocol (Optional string.) – Protocol used to contact visualization server
Returns: None.
Return type: None.
- Example: Standard
import graphistry graphistry.register(key="my api key")
- Example: Developer
import graphistry graphistry.register('my api key', server='staging', protocol='https')
- Example: Through environment variable
- ::
- export GRAPHISTRY_API_KEY = ‘my api key’
- ::
- import graphistry graphistry.register()
-
graphistry.pygraphistry.
server
(value=None)¶ Get the hostname of the server or set the server using hostname or aliases. Supported aliases: ‘localhost’, ‘staging’, ‘labs’. Also set via environment variable GRAPHISTRY_HOSTNAME.
-
graphistry.pygraphistry.
settings
(height=None, url_params={})¶