This simple example from our quickstart walkthrough introduces the basics of PyGraphistry. We also have more advanced tutorials avaiable.
You can download this notebook to run it locally.
import pandas
import graphistry
graphistry.register(key='Email pygraphistry@graphistry.com to get your API key')
# Parse CSV using Pandas
links = pandas.read_csv('data/lesmiserables.csv')
# Let's have a peak at our data by printing the first three rows
links[:3]
source | target | value | |
---|---|---|---|
0 | Napoleon | Myriel | 1 |
1 | Mlle.Baptistine | Myriel | 8 |
2 | Mme.Magloire | Myriel | 10 |
# Plot graph using the source/target columns as source/destination of edges
plotter = graphistry.bind(source='source', destination='target')
plotter.plot(links)
# New graph adding the number of encounters to edge labels.
links['label'] = links.value.map(lambda v: 'Num. Encounters: %d' % v)
plotter = plotter.bind(edge_label='label')
plotter.plot(links)
We are going to use Igraph to color nodes by community and size them using pagerank. To install igraph, use pip install python-igraph
# Convert our graph from Pandas to Igraph
import igraph
ig = plotter.pandas2igraph(links)
igraph.summary(ig)
IGRAPH D--- 77 254 -- + attr: __nodeid__ (v), label (e), value (e)
WARNING: "node" is unbound, automatically binding it to "__nodeid__".
# We create two node attributes for pagerank and community
ig.vs['pagerank'] = ig.pagerank()
ig.vs['community'] = ig.community_infomap().membership
igraph.summary(ig)
IGRAPH D--- 77 254 -- + attr: __nodeid__ (v), community (v), pagerank (v), label (e), value (e)
# The plotter can plot Igraph directly
plotter.bind(point_color='community', point_size='pagerank').plot(ig)