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

查看:232
本文介绍了在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()

从交互式shell运行时,其中 plt.ion()已被调用,不需要 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()对于交互式会话是可以的,但是n ot推荐用于脚本

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天全站免登陆