I am making interactive worksheets in Jupyter Notebook, introducing people to NetworkX. Suddenly, the nx.draw() command is not creating an output of a graph. It was working fine before, and I haven't changed anything about the code I was using. For example, one block of code that was working fine before was:
import networkx as nx
G2 = nx.Graph()
G2.add_nodes_from([1,2,3,4,5,6,7])
edgelist = [(1,4),(1,6),(1,7),(2,5),(2,6),(3,7),(4,6),(4,7),(5,7),(6,7)]
G2.add_edges_from(edgelist)
nx.draw_networkx(G2, with_labels=True, node_color = 'y')
Now, no errors come up, but neither does a graph. I have looked and seen that other people fixed this issue bu using plt.show() but I don't understand why I suddenly need to include that when I didn't have to before. Does anyone know a way I can avoid importing matplotlib and using the plt.show() command?
Perhaps the issue is to do with some other package I have or something to do with jupyter notebook?
EDIT: It has been pointed out to me that matplotlib is a package dependency so technically there is no way of drawing a graph in networkx without using matplotlib. I understand that, but is there a way to do it without explicitly calling matplotlib?
matplotlibis a package dependency, you can't.matplotlibmake it required. I just know it's now required.nx.__version__and!jupyter --versionfrom within the notebook?nx.versionis'2.6.2'and the output of!jupyter --versionisjupyter core: 4.7.1, jupyter-notebook: 6.4.3, qtconsole: 5.1.0, ipython: 7.26.0, ipykernel: 5.3.4, jupyter client: 6.1.12, jupyter lab: 3.1.7, nbconvert: 6.1.0, ipywidgets: 7.6.3, nbformat: 5.1.3, traitlets: 5.0.5