N
Horizon Insight News

'_AxesStack' object is not callable while using networkx to plot

Author

Andrew Thornton

Updated on March 02, 2026

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 

4 Answers

Start using

nx.draw_networkx(G, with_labels=True) 

instead of

nx.draw(G, with_labels=True) 
1

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:

enter image description here

EDIT:

Please consider this answer from Mohamad Sobhi if you are using networkx v3.1, and do not wish to downgrade Matplotlib.

8

The error is related to a deprecated feature of matplotlib. The problem is occurred because you are running networkx version 2.8.4. (The most recent stable version of networkx now is ver. 3.0.0).

Based on your explanation, I suppose you're using the conda environment, which you can find at . The most recent version is still 2.8.4.

I think the solution for your problem are.

  • Remove the networkx package from your conda environment (conda uninstall networkx)
  • Instead of using conda install, use pip install (pip install networkx)
  • Verify that your current networkx version is now ver 3.
  • I don't have rep to comment directly on @medium-dimensional. But check if you're managing your env in pycharm with conda. After having the same issue realised that latest version through conda still (until the day of this reply) 2.8.4.

    My suggestion trying to run

    conda activate <your env> pip install --update networkx 

    pip should catch that you already have the package installed and will update to version 3.0 in that very location

    1

    ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobm1paG6CeX2Omq%2Beq6OprqS3jKiZo52TqXqqv4ynpq1lk5a5ra3BpZxmr5ieuaZ51Kygp59do7K1w86rorFlpKR6sbjOrQ%3D%3D