[英]Node has no position in Networkx
The code is trying to plot a networkx Graph, and add colors on node, however, it told me that error on NetworkXError: Node 'Contact2' has no position
. 代码试图绘制networkx Graph,并在节点上添加颜色,但是,它告诉我NetworkXError: Node 'Contact2' has no position
。
import pandas as pd
%matplotlib notebook
import matplotlib.pyplot as plt
import networkx as nx
import numpy as np
G = nx.DiGraph()
G.add_edge('Owner','Contact1')
G.add_edge('Owner','Conatct2')
G.add_edge('Contact1','Firm1')
G.add_edge('Conatct2','Firm2')
G.add_edge('Firm1','Org1')
G.add_edge('Firm1','Org2')
G.add_edge('Firm2','Org3')
pos=nx.spring_layout(G)
nx.draw_networkx(G)
nx.draw_networkx_nodes(G,pos,
nodelist=['Owner'],
node_color='k',
node_size=500,
alpha=0.8)
nx.draw_networkx_nodes(G,pos,
nodelist=['Contact1','Contact2'],
node_color='r',
node_size=500,
alpha=0.8)
nx.draw_networkx_nodes(G,pos,
nodelist=['Firm1','Firm2'],
node_color='#8B8378',
node_size=500,
alpha=0.8)
nx.draw_networkx_nodes(G,pos,
nodelist=['Org1','Org2','Org3'],
node_color='r',
node_size=500,
alpha=0.8)
You just have a misspelling: 你只是拼错了:
G.add_edge('Owner','Conatct2')
You have a Conatct2
node. 你有一个Conatct2
节点。 You should replace it with Contact2
. 你应该用Contact2
替换它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.