%matplotlib inline

import networkx as nx
import matplotlib.pyplot as plt

"""
Explanation: Make graphs in Python with NetworkX
TODO
* https://networkx.github.io/index.html
* https://github.com/networkx/notebooks
* https://networkx.readthedocs.io/en/stable/examples/drawing/labels_and_colors.html
End of explanation
"""


g = nx.Graph()

g.add_node("Foo")
g.add_edge("Foo", 1)
g.add_edge(1, 2)
g.add_edge(1, 3)
g.add_edge(1, 4)
g.add_edge(3, 4)

list(g.nodes())

list(g.edges())

pos = nx.spring_layout(g)

nx.draw_networkx(g, pos, node_color='#ffaaff', node_size=800)

#plt.savefig("ex1.png")
plt.show()

"""
Explanation: Example 1
End of explanation
"""


g = nx.Graph()
g.add_edges_from([(0, 1), (0, 2), (0, 3), (1, 2)])

list(g.nodes())

list(g.edges())

pos = nx.spring_layout(g)

nx.draw_networkx_nodes(g, pos, node_size=20)
nx.draw_networkx_edges(g, pos, alpha=0.4)

#plt.savefig("ex2.png")
plt.show()

"""
Explanation: Example 2
End of explanation
"""


g = nx.gnm_random_graph(10, 20)

list(g.nodes())

list(g.edges())

pos = nx.spring_layout(g)

nx.draw_networkx_nodes(g, pos, node_size=20)
nx.draw_networkx_edges(g, pos, alpha=0.4)
nx.draw_networkx_labels(g, pos, alpha=0.4)

#plt.savefig("random_graph1.png")
plt.show()

"""
Explanation: Random graph
End of explanation
"""


