我正在matplotlib
内使用pycharm
绘制邻接矩阵
这是我的代码:
from matplotlib import pyplot, patches
import networkx as nx
import numpy as np
import scipy as sp
from scipy import io
rgraph = nx.read_edgelist("wv.txt")
adjMatrix = nx.to_numpy_matrix(rgraph, dtype=np.bool, nodelist=None)
len(adjMatrix)
fig = pyplot.figure(figsize=(5, 5))
print("plotting...")
pyplot.imshow(adjMatrix, cmap="Greys", interpolation="none")`
并获得此错误:
Exception in Tkinter callback
Traceback (most recent call last):
...
File "C:\pyenv35\lib\site-packages\matplotlib\cm.py", line 260, in to_rgba
x = ma.asarray(x)
File "C:\pyenv35\lib\site-packages\numpy\ma\core.py", line 7652, in asarray
subok=False, order=order)
File "C:\pyenv35\lib\site-packages\numpy\ma\core.py", line 2766, in __new__
order=order, subok=True, ndmin=ndmin)
MemoryError
数据(这是一个示例。文件有更多节点。在8298
附近):
30 1412
30 3352
30 5254
30 5543
30 7478
3 28
3 30
3 39
3 54
3 108
3 152
3 178
3 182
3 214
3 271
3 286
3 300
3 348
3 349
3 371
3 567
3 581
3 584
3 586
3 590
3 604
3 611
3 8283
25 3
25 6
25 8
25 19
25 23
25 28
25 29
...
请注意:当我用R语言读取文件/图表时,邻接矩阵有8298
行和列。
它在numpy内部触发内存错误。可能的原因是什么?任何提示?