from communities.algorithms import louvain_method
from communities.visualization import draw_communities
import numpy as np
adj_matrix = np.array([
[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5]
])
communities, frames = louvain_method(adj_matrix)
draw_communities(adj_matrix, communities)
参考https://github.com/shobrook/communities 写的demo 老是报错
具体的报错信息:
D:\Apps\Anaconda\python.exe D:/PYproject/UnderPower/test.py
D:\Apps\Anaconda\lib\site-packages\communities\visualization\draw_communities.py:89: MatplotlibDeprecationWarning:
The set_offset_position function was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
collection.set_offset_position("data")
AttributeError: 'NoneType' object has no attribute 'close'
Exception ignored in: 'scipy.spatial.qhull._Qhull.__dealloc__'
Traceback (most recent call last):
File "D:\Apps\Anaconda\lib\site-packages\communities\visualization\draw_communities.py", line 95, in _convex_hull_vertices
hull = ConvexHull(points)
AttributeError: 'NoneType' object has no attribute 'close'
Traceback (most recent call last):
File "D:/PYproject/UnderPower/test.py", line 13, in <module>
draw_communities(adj_matrix, communities)
File "D:\Apps\Anaconda\lib\site-packages\communities\visualization\draw_communities.py", line 220, in draw_communities
draw_community_patches(nodes, communities, ax)
File "D:\Apps\Anaconda\lib\site-packages\communities\visualization\draw_communities.py", line 164, in draw_community_patches
vertices = _convex_hull_vertices(node_coordinates, community)
File "D:\Apps\Anaconda\lib\site-packages\communities\visualization\draw_communities.py", line 95, in _convex_hull_vertices
hull = ConvexHull(points)
File "qhull.pyx", line 2433, in scipy.spatial.qhull.ConvexHull.__init__
File "qhull.pyx", line 270, in scipy.spatial.qhull._Qhull.__init__
File "messagestream.pyx", line 36, in scipy._lib.messagestream.MessageStream.__init__
OSError: Failed to open file b'C:\\Users\\\xe9\x9d\x99\xe9\x9d\x99\\AppData\\Local\\Temp\\scipy-jvppooms'
Process finished with exit code 1
原因:temp路径有中文
在系统环境变量中更改temp变量值为不含中文的