Python, networkx does not draw a graph

According to the article on the site, I decided to draw a simple graph using networkX. I did everything according to the instructions, but for some reason nothing happens after executing the code. The author of the article, as well as other authors, write that visualization occurs through matplotlib, but for some reason they import it, but do not use it. In general, in theory, after executing the code, a garf of 3 edges should be drawn, but nothing is drawn, I give the code below:

import itertools
import networkx as nx
import numpy.random as rnd
import matplotlib.pyplot as plt

def add_nodes(nodes): # Упрощаем добавление вершин
    for i in nodes:
        graph.add_node(i)

def add_edge(f_item, s_item, graph):
    graph.add_edge(f_item, s_item)
    graph.add_edge(s_item, f_item) 


graph = nx.Graph()
add_nodes(('A','B','C'))

add_edge('A','B', graph)
add_edge('B','C', graph)


nx.draw_circular(graph,
         node_color='red',
         node_size=1000,
         with_labels=True)

1 answers

Just add the following line to the end:

plt.show()

Result

UPDATE. As requested in the comment

import itertools
import networkx as nx
import numpy.random as rnd
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

img = mpimg.imread('img_avatar_3.png')


def add_nodes(nodes):  # Упрощаем добавление вершин
    for i in nodes:
        graph.add_node(i, image=img)


def add_edge(f_item, s_item, graph):
    graph.add_edge(f_item, s_item)
    graph.add_edge(s_item, f_item)


graph = nx.Graph()
add_nodes(('A', 'B', 'C'))

add_edge('A', 'B', graph)
add_edge('B', 'C', graph)

pos = nx.circular_layout(graph)

fig = plt.figure(figsize=(5, 5))
ax = plt.subplot(111)
ax.set_aspect('equal')
nx.draw_networkx_edges(graph, pos, ax=ax)

plt.xlim(-1.5, 1.5)
plt.ylim(-1.5, 1.5)

trans = ax.transData.transform
trans2 = fig.transFigure.inverted().transform

piesize = 0.2  # this is the image size
p2 = piesize / 2.0
for n in graph:
    xx, yy = trans(pos[n])  # figure coordinates
    xa, ya = trans2((xx, yy))  # axes coordinates
    a = plt.axes([xa - p2, ya - p2, piesize, piesize])
    a.set_aspect('equal')
    a.imshow(graph.nodes[n]['image'])
    a.axis('off')
ax.axis('off')

plt.show()

enter a description of the image here

 4
Author: Serg Bocharov, 2020-09-08 19:27:20