在散点图上显示节点编号

时间:2019-06-09 10:01:39

标签: python-3.x matplotlib network-analysis

我正在尝试可视化网络节点的网络中心度和中间度

T是我的datacamp工作区中加载的网络(已经尝试将其加载到pycharm中)。

我以x轴为中间性中心,以y轴为度中心性。 我想要得到的是标签-情节中每个点的节点号

# Compute the betweenness centrality of T: bet_cen
bet_cen = nx.betweenness_centrality(T)

# Compute the degree centrality of T: deg_cen
deg_cen = nx.degree_centrality(T)

n=list(T.nodes())

# Create a scatter plot of betweenness centrality and degree centrality
plt.scatter(list(bet_cen.values()),list(deg_cen.values()))

for i,txt in enumerate(n):
    plt.annotate(txt, (list(bet_cen.values()),list(deg_cen.values())))

# Display the plot
plt.show()

我收到此错误

Error in callback <bound method FiguresManager.matplotlib_show of <class 'pythonbackend.matplotlib_plots.FiguresManager'>> (for matplotlib_show):
Traceback (most recent call last):
  File "<stdin>", line 16, in <module>
    plt.show()
  File "<stdin>", line 254, in show
    return _show(*args, **kw)
  File "<stdin>", line 107, in show
    get_ipython().events.trigger("matplotlib_show", fig_manager.canvas)
  File "<stdin>", line 77, in trigger
    self.shell.showtraceback()
  File "<stdin>", line 1832, in showtraceback
    self._showtraceback(etype, value, stb)
  File "<stdin>", line 69, in exceptionCatcher
    raise exception
  File "<stdin>", line 74, in trigger
    func(*args, **kwargs)
  File "<stdin>", line 51, in matplotlib_show
    cls.FIGURES.append(MatplotlibFigure(canvas, cls.HEIGHT, cls.WIDTH))
  File "<stdin>", line 24, in __init__
    canvas.print_svg(self.FILE_PATH, facecolor="white")
  File "<stdin>", line 1193, in print_svg
    return self._print_svg(filename, svgwriter, **kwargs)
  File "<stdin>", line 1248, in _print_svg
    self.figure.draw(renderer)
  File "<stdin>", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "<stdin>", line 1299, in draw
    renderer, self, artists, self.suppressComposite)
  File "<stdin>", line 138, in _draw_list_compositing_images
    a.draw(renderer)
  File "<stdin>", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "<stdin>", line 2437, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File "<stdin>", line 138, in _draw_list_compositing_images
    a.draw(renderer)
  File "<stdin>", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "<stdin>", line 2299, in draw
    xy_pixel = self._get_position_xy(renderer)
  File "<stdin>", line 1888, in _get_position_xy
    return self._get_xy(renderer, x, y, self.xycoords)
  File "<stdin>", line 1740, in _get_xy
    x = float(self.convert_xunits(x))
TypeError: float() argument must be a string or a number, not 'list'

0 个答案:

没有答案