Practice Mining the Social Web Book


In [19]:
import networkx as nx
g = nx.Graph()
g.add_edge(1,2)
g.add_node("spam")
print g.nodes()


[1, 2, 'spam']

In [20]:
print g.edges()


[(1, 2)]

In [21]:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
nx.draw(g)
plt.show()


  • In order for inline graphics to work %matplotlib inline
  • In order to save graphics call matplotlib.use("Agg")

In [22]:
plt.savefig("1stgraph.png", dpi=100)


<matplotlib.figure.Figure at 0x10c35c150>