Skip to content

Instantly share code, notes, and snippets.

@joshz
Created June 19, 2012 15:17
Show Gist options
  • Save joshz/2954731 to your computer and use it in GitHub Desktop.
Save joshz/2954731 to your computer and use it in GitHub Desktop.
A is not B
import networkx as nx
import matplotlib.pyplot as plt
isnot = [('Spain', 'Greece'),
('Portugal', 'Greece'),
('Greece', 'Ireland'),
('Spain', 'Ireland'),
('Spain', 'Portugal'),
('Ireland', 'Greece'),
('Portugal', 'Ireland'),
('Spain', 'Uganda'),
('Uganda', 'Spain')]
flat = list(set([country for c in isnot for country in c]))
G = nx.Graph()
for c in flat:
G.add_node(c)
G.add_edges_from(isnot)
H = nx.DiGraph(G)
nx.draw(H)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment