绘制networkx图时出现意外错误 [英] Unexpected error while drawing networkx graph

查看:297
本文介绍了绘制networkx图时出现意外错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的图形,需要在我的屏幕上绘制它,这是我的代码:

I have a simple graph and need to draw it on my screen, here is my code:

def gera_grafo(matriz):
grafo = nx.to_networkx_graph(matriz, create_using=nx.Graph)

nx.draw(grafo)
plt.show()

return grafo

其中矩阵是包含连接权重的邻接列表.coda 工作得很好,但我不得不创建一个新的 python virtualenv,从那时起,即使正确安装了所有必需的库,它也会在 nx.draw() 调用中引发错误.我得到的错误是:

Where matrix is an adjacency list containing the weights of the connections. The coda was working just fine, but i had to create a new python virtualenv and since then, even though all the required libraries are correctly installed it throws an error on the nx.draw() call. The error I got is:

    Traceback (most recent call last):
  File "/run/media/luisola/A216C03316C009ED/Users/Luis/Documents/Iniciação Científica/inicia-o-cient-fica/venv/lib/python3.9/site-packages/networkx/utils/decorators.py", line 396, in _random_state
    random_state_arg = args[random_state_index]
IndexError: tuple index out of range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/run/media/luisola/A216C03316C009ED/Users/Luis/Documents/Iniciação Científica/inicia-o-cient-fica/criacao_do_grafo.py", line 58, in <module>
    grafo = gera_grafo(matriz)
  File "/run/media/luisola/A216C03316C009ED/Users/Luis/Documents/Iniciação Científica/inicia-o-cient-fica/criacao_do_grafo.py", line 39, in gera_grafo
    nx.draw(grafo)
  File "/run/media/luisola/A216C03316C009ED/Users/Luis/Documents/Iniciação Científica/inicia-o-cient-fica/venv/lib/python3.9/site-packages/networkx/drawing/nx_pylab.py", line 123, in draw
    draw_networkx(G, pos=pos, ax=ax, **kwds)
  File "/run/media/luisola/A216C03316C009ED/Users/Luis/Documents/Iniciação Científica/inicia-o-cient-fica/venv/lib/python3.9/site-packages/networkx/drawing/nx_pylab.py", line 333, in draw_networkx
    pos = nx.drawing.spring_layout(G)  # default to spring layout
  File "/run/media/luisola/A216C03316C009ED/Users/Luis/Documents/Iniciação Científica/inicia-o-cient-fica/venv/lib/python3.9/site-packages/decorator.py", line 214, in fun
    return caller(func, *(extras + args), **kw)
  File "/run/media/luisola/A216C03316C009ED/Users/Luis/Documents/Iniciação Científica/inicia-o-cient-fica/venv/lib/python3.9/site-packages/networkx/utils/decorators.py", line 400, in _random_state
    raise nx.NetworkXError("random_state_index is incorrect") from e
networkx.exception.NetworkXError: random_state_index is incorrect

这是我的代码错误吗?如果是这样,我该怎么办?提前致谢

Is this an error on my code? If so, what can i do? Thanks in advance

推荐答案

如该问题所述:networkx 显示 random_state_index 不正确他们是 decorator=5.0.0 的问题.如 GitHub 上的相关问题中所述 (https://github.com/networkx/networkx/issues/4718) decorator>=5.0.X 应该很快就可以使用了.因此,请稍等片刻,按照上面 SO 问题中的建议升级或降级到旧版本.

As stated for this question: networkx shows random_state_index is incorrect Their was a problem with decorator=5.0.0. As discussed in the related issue on GitHub (https://github.com/networkx/networkx/issues/4718) decorator>=5.0.X should be available soon. So either wait a little bit to upgrade or downgrade to an old version as suggested in the SO question above.

如上面链接的问题所述,装饰器现已更新和修复.

As discussed in the issue linked above, decorator has now been updated and fixed.

这篇关于绘制networkx图时出现意外错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆