When drawing a graph, it is impossible to set specific labels for each node. According to the documentation, the draw_networkx_labels method is used for drawing labels, but for some reason it does not work (although I did it before).

Here is the code used:

import networkx as nx import matplotlib.pyplot as plt edges = [(0, 2), (1, 2), (2, 3), (2, 4)] G = nx.Graph() G.add_edges_from(edges) pos = nx.spring_layout(G) # получим метки узлов # 1 -> 111 labels = dict((i, str(i)*3) for i in range(5)) # рисуем граф nx.draw_networkx(G, pos=pos, with_labels=False) # рисуем метки nx.draw_networkx_labels(G, pos=pos, labels=labels) plt.savefig('labels.png') 

It should work like this, but it does not work: enter image description here

As it turned out, this problem appears in pycharm, while in jupyter notebook it works out as it should.

  • and what will not suit you in the picture of the graph? - MaxU 5:19 pm
  • @MaxU what is in the picture is what I would like to receive. - garrythehotdog
  • one
    running your code, I get what is in the picture, only the nodes are rotated slightly clockwise ... - MaxU
  • What are your NetworkX and matplotlib ? - MaxU
  • one
    @MaxU Thank you very much, now I would like to understand which way to dig. - garrythehotdog

0