0

我想生成可重现的图。Withnetworkx可以将随机状态传递给布局。那是为了保证情节是一样的。当对全息视图做同样的事情时,我得到了一个错误。

%pylab inline

import pandas as pd
import networkx as nx
import holoviews as hv

# generating the graph
G = nx.Graph()
ndxs = [1, 2, 3, 4]
G.add_nodes_from(ndxs)
G.add_weighted_edges_from([(1,2,0), (1,3,1), (1,4,-1),
                           (2,4,1), (2,3,-1), (3,4,10)]) 

# drawing with networkx
nx.draw(G, nx.spring_layout(G, random_state=100))


# drawing with holoviews/bokeh
hv.extension('bokeh')
%opts Graph [width=400 height=400]
layout = nx.layout.spring_layout(G, random_state=100)
hv.Graph.from_networkx(G, layout)
>>> TypeError: 'dict' object is not callable
4

1 回答 1

0

第一个问题是该Graph.from_networkx方法接受布局函数而不是该函数输出的字典。如果您想将参数传递给函数,您可以将其作为关键字参数,例如:

hv.Graph.from_networkx(G, nx.layout.spring_layout, random_state=42)

在我的 networkx 版本中random_state,布局函数不接受参数,在这种情况下,您可以直接使用 NumPy 设置种子:

np.random.seed(42)
hv.Graph.from_networkx(G, nx.layout.spring_layout)
于 2018-05-24T11:19:44.543 回答