import matplotlib.pyplot as plt
import networkx as nx
import numpy as np
A = [[0, 1.51, 0, 1.71, 0],
[0, 0, 2.11, 1.81, 2.31],
[0, 0, 0, 1.31, 1.41],
[0, 0, 0, 0, 1.11],
[0, 0, 0, 0, 0]]
G = nx.from_numpy_matrix(np.matrix(A), create_using=nx.DiGraph)
layout = nx.spring_layout(G)
labels = nx.get_edge_attributes(G, "weight")
# a list of the node labels in the right order
raw_labels = ["A1", "K2", "D3", "E4", "Z30"]
lab_node = dict(zip(G.nodes, raw_labels))
print("Degree centrality weight")
d = G.degree(weight='weight')
print(d)
for x in d:
if x[1] > 4:
large = x
print (large)
else:
small = x
print (small)
nx.draw(G, layout)
nx.draw_networkx_nodes(G, layout, edgelist=large, node_size=100)
nx.draw_networkx_nodes(G, layout, edgelist=small, node_size=1500)
nx.draw_networkx_edge_labels(G, layout, edge_labels=labels)
nx.draw_networkx_labels(G, layout, labels=lab_node, font_size=10, font_family='sans-serif')
plt.show()
答案 0 :(得分:0)
以下代码有效。在您的代码中存在一些问题:首先,就像乔尔在注释中提出的那样,您使用了using(WebClient webclient = new WebClient())
{
webclient.Encoding = UTF8Encoding.UTF8;
webclient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
webclient.UseDefaultCredentials = true;
blankString="";
webclient.UploadString(url, blankString);
webclient.UploadString(url, stringToUpload);
}
和small
作为变量,但希望将它们列出。其次,您在draw_networkx_nodes
中使用了large
而不是edgelist
。
我将nodelist
替换为nx.draw
(并添加了nx.draw_networkx_edges
),以允许其他用户绘制的节点尺寸小于或小于默认尺寸,因为较小的尺寸不适用于plt.axis("off")
。
作为最后的个人建议,我将用更长的自我解释名称(例如nx.draw
,{{)替换变量名称(例如d
,G
或small
) 1}},node_degrees
。
graph