【问题标题】:hovering over matplotlib node悬停在 matplotlib 节点上
【发布时间】:2021-04-10 00:12:52
【问题描述】:

我正在尝试使用networkxmatplotlib,我想在将鼠标悬停在节点上时获取节点的名称。我正在尝试使用 mpld3 库,但似乎遇到了递归错误。

graph_nx = graph.to_networkx(max_vertices)
pos = nx.spring_layout(graph_nx)

fig, ax = plt.subplots(subplot_kw=dict(facecolor='#EEEEEE'))
scatter = nx.draw_networkx_nodes(graph_nx, pos, ax=ax, node_size=120)
nx.draw_networkx_edges(graph_nx, pos, ax=ax, width=0.5)

labels = graph_nx.nodes().keys()
tooltip = mpld3.plugins.PointLabelTooltip(scatter, labels=labels)
mpld3.plugins.connect(fig, tooltip)

mpld3.show()

这就是我现在拥有的。

【问题讨论】:

  • 当你有错误时,把它放在帖子上,而不是仅仅提及你有它。

标签: python matplotlib networkx


【解决方案1】:

我相信标签需要列表数据类型。您是否检查过graph_nx.nodes().keys() 是否返回列表。您可能希望使用 .tolist() 将其转换为列表。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-01
    • 2023-04-08
    • 1970-01-01
    • 2012-12-15
    • 2011-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多