[英]plt.show() will not work when I attempt plot a degree distribution but it works when I plot a random graph
I'm new to python so forgive me if this is a simple question. 我是python的新手,所以如果这是一个简单的问题,请原谅我。
I am trying to plot a graph with matplot and have been unsuccessful. 我正在尝试使用matplot绘制图形,但未成功。 I'm using network x and when I use plt.show() to show a graph I randomly generated it works fine.
我正在使用网络x,当我使用plt.show()来显示我随机生成的图形时,它工作正常。 But when I attempt to use it to plot a degree distribution nothing happens.
但是,当我尝试使用它绘制度分布时,什么也没有发生。
I suspect I am not correctly adding a subplot but I am really clueless after that. 我怀疑我没有正确添加子图,但此后我真的很笨。
Here is my code so far: 到目前为止,这是我的代码:
import networkx as nx
import matplotlib.pyplot as plt
p=1.0/6.0
g=nx.erdos_renyi_graph(10,p)
nx.draw(g)
plt.show()
def deg_dist()
deg = {}
for n in g.nodes():
d = g.degree(n)
if d not in deg:
deg[d] = 0
deg[d] += 1
items = sorted(deg.items())
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([k for (k,v) in items], [v for (k,v) in items ])
plt.title('Degree Distribution')
fig.show()
Forgive me if I'm wrong but... Did you at least call this deg_dist
function ? 如果我错了,请原谅我,但是...您至少调用过
deg_dist
函数吗? If not, well nothing will happen here. 如果没有,那么这里什么也不会发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.