#!/usr/bin/env python # coding: utf-8 # # Quickstart: Graphing Les Misérables # # This simple example from our [quickstart walkthrough](http://graphistry.github.io/pygraphistry/index.html#quickstart-graph-les-misérables) introduces the basics of PyGraphistry. We also have more advanced tutorials avaiable. # # You can [download this notebook](https://github.com/graphistry/pygraphistry/tree/master/demos) to run it locally. # In[1]: import pandas import graphistry graphistry.register(key='Email pygraphistry@graphistry.com to get your API key') # In[2]: # Parse CSV using Pandas links = pandas.read_csv('data/lesmiserables.csv') # In[3]: # Let's have a peak at our data by printing the first three rows links[:3] # In[4]: # Plot graph using the source/target columns as source/destination of edges plotter = graphistry.bind(source='source', destination='target') plotter.plot(links) # In[5]: # 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) # ### Controling Node Size and Color # We are going to use Igraph to color nodes by community and size them using pagerank. To install igraph, use `pip install python-igraph` # In[6]: # Convert our graph from Pandas to Igraph import igraph ig = plotter.pandas2igraph(links) igraph.summary(ig) # In[7]: # We create two node attributes for pagerank and community ig.vs['pagerank'] = ig.pagerank() ig.vs['community'] = ig.community_infomap().membership igraph.summary(ig) # In[8]: # The plotter can plot Igraph directly plotter.bind(point_color='community', point_size='pagerank').plot(ig)