Following one of online tutorials I found it difficult to run even a small piece of paragraph. Here is what I want to write into the graph: a Directed acyclic unweighted matrix into the graph, however I encountered the problem of matrix-representing and pic-representing. The former gives a warning and substitutes output matrix with arrays. However the pic plotting is always output only errors I don't know why. Here is my code
import networkx as nx
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('TkAgg')
import numpy as np
A = np.array([[0,1,1,0],
[1,0,1,1],
[1,1,0,0],
[0,1,0,0]])
G=nx.from_numpy_array(A)
nx.draw(G,with_lables=True)
And my networkx version is 2.8.4, matplotlib version is 3.6.0, matching the versions tutorial mentioned. Here is the error:
'_AxesStack' object is not callable
Start using
nx.draw_networkx(G, with_labels=True)
instead of
nx.draw(G, with_labels=True)
The argument that draw() supports is with_labels. Please fix your typo.
The error has been discussed on this thread of networkx's GitHub repository, and suggests users with matplotlib 3.6.0rc1 to update networkx to its latest version.
With the fixed typo, and networkx version 2.8.7 and matplotlib version 3.5.1, the code produces following figure:

EDIT:
Please consider this answer from Mohamad Sobhi if you are using networkx v3.1, and do not wish to downgrade Matplotlib.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With