python有向图,无向图绘制
https://www.jianshu.com/p/52bb142314ebR语言画网络图https://blog.csdn.net/fly_hawk/article/details/78513257python绘制无向图,输入数据import pandas as pdimport networkx as nximport matplotlib.pyplot as pltedges = pd.Da
·
https://www.jianshu.com/p/52bb142314ebR语言画网络图
https://blog.csdn.net/fly_hawk/article/details/78513257
python绘制无向图,输入数据
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
edges = pd.DataFrame()
edges['sources'] = [0,1,2,3,4,4,6,7,7,9,1,4,4,4,6,7,5,8,9,8]
edges['targets'] = [1,4,4,4,6,7,5,8,9,8,0,1,2,3,4,4,6,7,7,9]
#edges['weights'] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
G = nx.from_pandas_edgelist(edges, source='sources',target='targets')
nx.draw(G, with_labels=True,pos=None, arrows=True)
#plt.savefig("undirected_graph.png")
plt.show()
python绘制无向图,读取数据
import networkx as nx
import matplotlib.pyplot as plt
import pandas as pd
# 读取文件,获取节点和边
f = open("clustered_skill_name.txt", "r")
sources= []
targets = []
while True:
line = f.readline()
if line:
source=line.split('\t')[0]
target=line.split('\t')[1]
sources.append(source)
targets.append(target)
else:
break
f.close()
print (len(sources)) #图节点
print(sources)
print(targets)
# 有向图绘制
edges = pd.DataFrame()
edges['sources']=sources
edges['targets'] =targets
G = nx.from_pandas_edgelist(edges, source='sources',target='targets')
nx.draw_networkx(G, pos=None, arrows=True, with_labels=True)
plt.savefig('assitment2009.png')
plt.show()
部分txt 文件数据
w
更多推荐
已为社区贡献1条内容
所有评论(0)