# UN-DIRECTED
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_edges_from([("jack","sally"),("jack","diane"),("jack","joe"),("joe","diane"),("diane","sally"),("jack","jill")])
fig, ax = plt.subplots()
fig.set_size_inches(12, 12)
nx.draw(G,
with_labels=True,
# labels=labels,
node_color='blue',
width=3,
node_size=4000,
font_color='white',
font_size=18,
ax=ax
)
plt.show()
# START FRESH (delete output folder and re-create)
import os
import shutil
dirpath="./output-1"
if os.path.exists(dirpath) and os.path.isdir(dirpath):
shutil.rmtree(dirpath)
os.mkdir(dirpath)
# EXPORT
nx.write_adjlist(G, dirpath+'/example.adjlist')
nx.write_multiline_adjlist(G, dirpath+'/example.mult-adjlist')
nx.write_edgelist(G, dirpath+'/example.edgelist')
nx.write_gml(G, dirpath+'/example.gml')
nx.write_gexf(G, dirpath+'/example.gexf')
nx.write_graphml(G, dirpath+'/example.graphml')