在 NetworkX 中绘制图形 [英] Draw graph in NetworkX

查看:38
本文介绍了在 NetworkX 中绘制图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 NetworkX 中绘制任何图形,但什么也没得到,甚至错误:

I'm trying to draw any graph in NetworkX, but get nothing, not even errors:

import networkx as nx
import matplotlib.pyplot as plt
g1=nx.petersen_graph()
nx.draw(g1)

推荐答案

添加到最后:

plt.show()

<小时>

import networkx as nx
import matplotlib.pyplot as plt
g1 = nx.petersen_graph()
nx.draw(g1)
plt.show()

当从调用了 plt.ion() 的交互式 shell 运行时,不需要 plt.show().这可能就是为什么在很多例子中都省略了它的原因.

When run from an interactive shell where plt.ion() has been called, the plt.show() is not needed. This is probably why it is omitted in a lot of examples.

如果您从脚本(其中未调用 plt.ion())运行这些命令,则需要 plt.show().plt.ion() 适用于交互式会话,但是 不推荐用于脚本.

If you run these commands from a script (where plt.ion() has not been called), the plt.show() is needed. plt.ion() is okay for interactive sessions, but is not recommended for scripts.

这篇关于在 NetworkX 中绘制图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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