Skip to content

Instantly share code, notes, and snippets.

@nullset2
Last active October 2, 2016 06:42
Show Gist options
  • Select an option

  • Save nullset2/5c85da67b1bdedc38b3800958f5dfac4 to your computer and use it in GitHub Desktop.

Select an option

Save nullset2/5c85da67b1bdedc38b3800958f5dfac4 to your computer and use it in GitHub Desktop.
import networkx as nx
import matplotlib
import matplotlib.pyplot as plt
def read_graph():
graph_adjacency_list = { }
for line in open("input.txt"):
line = map(int, line.rstrip("\t\r\n").split("\t"))
graph_adjacency_list.update({ line[0]: { e: 1 for e in line[1:] } })
return graph_adjacency_list
graph_data = read_graph()
G = nx.Graph(graph_data)
nx.draw_networkx(G, with_labels = True, node_color = "c", edge_color = "k", font_size = 8)
plt.axis('off')
plt.draw()
plt.savefig("graph.pdf")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment