I am new to using Tkinter and networkx python libraries i want to plot a graph but i got the following error
def plot_actual():
pos=nx.get_node_attributes(G,'pos')
fig, ax = plt.subplots(figsize=(40, 30),dpi=100)
nx.draw_networkx_nodes(G, pos,with_labels=True,ax=ax) // LINE 601
labels = nx.get_edge_attributes(G,'weight')
nx.draw_networkx_labels(G,pos)
nx.draw_networkx_edge_labels(G,pos,edge_labels=labels)
nx.draw_networkx_edges(G,pos,edge_labels=labels) // LINE 605
ax.tick_params(left=True, bottom=True, labelleft=True, labelbottom=True)
path=('ActualGraph.png')
plt.savefig(path)
img = PImage.open(path)
img.show()
return
i got an error on nx.draw_networkx_nodes but i did not get the actual reason for this
1st error i got in line 627 (i mention the line in code snippet too)
root = Tk()
root.geometry('1200x900')
my_font = Font(family="Times New Roman", size=20, weight="bold" )
Label(root, text="" ,font=my_font).pack()
Label(root, text="Select A .txt File From Your System" ,font=my_font).pack()
btn1 = Button(root, text ='Open', command = lambda:open_file())
btn1.pack(pady = 20)
btn2 = Button(root, text ='SeeActualGraph',command = lambda:plot_actual()) //LINE 627
btn2.pack(pady = 20)
if anyone know what's the problem please let me know
CodePudding user response:
The error indicates that the line nx.draw_networkx_edges(G,pos,edge_labels=labels)
has been given an invalid keyword argument.
nx.draw_networkx_edges
can't be called with edge_labels=labels.
I'm not very experienced with networkx, but my guess is that you have already given all the edges labels with the previous line, so just calling nx.draw_networkx_edges(G,pos)
might work.
Also the traceback isn't a list of errors. You only got one error, the traceback lists all the calls that are on the stack. For your case, the error occurred when you tried line 605, line 605 was called in turn by line 627, which was called in turn by line 1892.