I am testing out how to create network graphs on "networkx"; my problem is that when I try plotting these graphs using "matplotlib", the nodes, edges, and labels appear jumbled. I want to have the labels attached to right node, and I want the edges to look like they are connecting the nodes.
code
import networkx as nx
try:
import matplotlib.pyplot as plt
except:
raise
g = nx.MultiGraph()
strList = ["rick james", "will smith", "steve miller", "rackem willie", "little tunechi", "ben franklin"]
strList2 = ["jules caesar", "atticus finch", "al capone", "abe lincoln", "walt white", "doc seuss"]
i = 0
while i < len(strList) :
g.add_edge(strList[i], strList2[i])
i = i + 1
nx.draw_networkx_nodes(g,pos = nx.spring_layout(g), nodelist = g.nodes())
nx.draw_networkx_edges(g,pos = nx.spring_layout(g), edgelist = g.edges())
nx.draw_networkx_labels(g,pos=nx.spring_layout(g))
#plt.savefig("testImage.png")
plt.show()
image
I want my connections to be like this:
rick james <--> jules caesar
will smith <--> atticus finch
steve miller <--> al capone
...etc
Any help/insight is greatly appreciated!