我正在尝试从一个numpy矩阵创建一个有向图。我正在测试不同的布局,并且对“点”程序有疑问。我的代码:
import networkx as nx
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pygraphviz
import pydotplus
from networkx.drawing.nx_agraph import graphviz_layout
network = pd.read_csv('Network.csv')
G = nx.from_numpy_matrix(network.values, create_using=nx.DiGraph())
pos = graphviz_layout(G, prog='dot')
pos
出现以下错误:
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-9-f4647c8efaf6> in <module>()
----> 1 pos = graphviz_layout(G, prog='dot')
2 pos
~/anaconda3/envs/brightway/lib/python3.6/site-packages/networkx/drawing/nx_agraph.py in graphviz_layout(G, prog, root, args)
241
242 """
--> 243 return pygraphviz_layout(G, prog=prog, root=root, args=args)
244
245
~/anaconda3/envs/brightway/lib/python3.6/site-packages/networkx/drawing/nx_agraph.py in pygraphviz_layout(G, prog, root, args)
276 args += "-Groot=%s" % root
277 A = to_agraph(G)
--> 278 A.layout(prog=prog, args=args)
279 node_pos = {}
280 for n in G:
~/anaconda3/envs/brightway/lib/python3.6/site-packages/pygraphviz/agraph.py in layout(self, prog, args)
1356 """
1357 fmt = 'dot'
-> 1358 data = self._run_prog(prog, ' '.join([args, "-T", fmt]))
1359 self.from_string(data)
1360 self.has_layout = True
~/anaconda3/envs/brightway/lib/python3.6/site-packages/pygraphviz/agraph.py in _run_prog(self, prog, args)
1333
1334 if not data:
-> 1335 raise IOError(b"".join(errors))
1336
1337 if len(errors) > 0:
OSError: b''
但是,使用带有prog ='neato'或'twopi'的graphviz_layout可以正常工作。我正在Mac OS High Sierra上使用python 3.6.6版的Jupyter笔记本中工作。