# -*- coding: utf-8 -*-
"""
Created on Wed Jul 14 16:46:02 2021
@author: Administrator
"""
import numpy as np
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
edges = pd.DataFrame()
edges['source'] = [1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5]
edges['targets'] = [2, 4, 5, 3, 1, 2, 5, 1, 5, 1, 3, 4]
edges['weights'] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
G = nx.from_pandas_edgelist(edges, source='source', target='targets', edge_attr='weights')
# 度
print(nx.degree(G))
# 连通分量
print(list(nx.connected_components(G)))
# 图直径
print(nx.diameter(G))
# 度中心性
print(nx.degree_centrality(G))
# 特征向量中心性
print(nx.eigenvector_centrality(G))
# betweenness
print(nx.betweenness_centrality(G))
# closeness
print(nx.closeness_centrality(G))
# pagerank
print(nx.pagerank(G))
# HITS
print(nx.hits(G))
nx.draw_networkx(G,pos=nx.circular_layout(G),with_labels=True)
plt.show()
图的基础指标
最新推荐文章于 2024-07-06 16:25:50 发布