<p>好吧,我差不多拿到了。我可以改变我想要的节点的颜色,但是它没有保持图形的相同形状,我还可以更新agraph来表示graphviz fdp格式。如果有人感兴趣,这里有一些变化:</p>
<pre><code>with open(counts, "r") as f2:
countsdic = defaultdict(list)
for line in f2:
k,v = line.strip().split()
countsdic[k].append(v)
with open(hybrids, "r") as f3:
hybrids = [line.strip() for line in f3]
print hybrids
tmp = []
for el in sum(edges, []):
tmp.append(el)
nodes = []
for t in tmp:
if t not in nodes:
nodes.append(t)
node_sizes = {}
for n in nodes:
node_sizes[n] = ' '.join(countsdic[n])
sizes = []
for v in node_sizes.values():
x = int(v) * 10
sizes.append(x)
g = nx.Graph()
#g.add_nodes_from(nodes)
g.add_edges_from(edges)
#for node in nodes:
# if node in hybrids:
# color = 'green'
# if node not in hybrids:
# color = 'blue'
pos=nx.graphviz_layout(g, prog='fdp')
nx.draw_networkx_nodes(g, pos, nodelist=[str(n) for n in nodes], node_color='b', node_size = sizes)
nx.draw_networkx_nodes(g, pos, nodelist=[str(n) for n in nodes if n in hybrids], node_color='g', node_size = sizes)
nx.draw_networkx_edges(g,pos)
#nxgraph(graph)
#for node in nodes:
# if node in hybrids:
# y.add_node(node, fillcolor='green')
# if node not in hybrids:
# g.add_node(node, fillcolor='blue')
A = nx.to_agraph(g)
A.layout(prog="fdp")
A.draw(inp + "2.png")
plt.figure(1,figsize=(2000,2000))
plt.savefig(out + ".png", dpi = 1000)
plt.show()
</code></pre>
<p>然而,使用fdp格式和agraph使所有内容变黑。如果有人能帮忙的话,我仍然想使节点具有特定的颜色。我还想保留图形的原始形状和格式,只要更改节点颜色,如果还有人可以帮忙的话。我会继续研究这个问题,如果我想出来的话,我会发布另一个答案。感谢所有看过这篇文章的人。(我无法发布更新后的图像,因为图像太大)</p>