当前位置: 首页>>代码示例>>Python>>正文


Python networkx.spectral_layout方法代码示例

本文整理汇总了Python中networkx.spectral_layout方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.spectral_layout方法的具体用法?Python networkx.spectral_layout怎么用?Python networkx.spectral_layout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkx的用法示例。


在下文中一共展示了networkx.spectral_layout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: draw_spectral

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import spectral_layout [as 别名]
def draw_spectral(G, **kwargs):
    """Draw networkx graph with spectral layout.

    Parameters
    ----------
    G : graph
       A networkx graph
    kwargs : optional keywords
       See hvplot.networkx.draw() for a description of optional
       keywords, with the exception of the pos parameter which is not
       used by this function.

    Returns
    -------
    graph : holoviews.Graph or holoviews.Overlay
       Graph element or Graph and Labels
    """
    return draw(G, nx.spectral_layout, **kwargs) 
开发者ID:holoviz,项目名称:hvplot,代码行数:20,代码来源:networkx.py

示例2: plot_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import spectral_layout [as 别名]
def plot_graph(plt, G):
    plt.title('num of nodes: '+str(G.number_of_nodes()), fontsize = 4)
    parts = community.best_partition(G)
    values = [parts.get(node) for node in G.nodes()]
    colors = []
    for i in range(len(values)):
        if values[i] == 0:
            colors.append('red')
        if values[i] == 1:
            colors.append('green')
        if values[i] == 2:
            colors.append('blue')
        if values[i] == 3:
            colors.append('yellow')
        if values[i] == 4:
            colors.append('orange')
        if values[i] == 5:
            colors.append('pink')
        if values[i] == 6:
            colors.append('black')
    plt.axis("off")
    pos = nx.spring_layout(G)
    # pos = nx.spectral_layout(G)
    nx.draw_networkx(G, with_labels=True, node_size=4, width=0.3, font_size = 3, node_color=colors,pos=pos) 
开发者ID:RexYing,项目名称:diffpool,代码行数:26,代码来源:util.py

示例3: _spectral

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import spectral_layout [as 别名]
def _spectral(A, dim=2):
    # Input adjacency matrix A
    # Uses dense eigenvalue solver from numpy
    try:
        import numpy as np
    except ImportError:
        raise ImportError("spectral_layout() requires numpy: http://scipy.org/ ")
    try:
        nnodes,_=A.shape
    except AttributeError:
        raise nx.NetworkXError(\
            "spectral() takes an adjacency matrix as input")

    # form Laplacian matrix
    # make sure we have an array instead of a matrix
    A=np.asarray(A)
    I=np.identity(nnodes,dtype=A.dtype)
    D=I*np.sum(A,axis=1) # diagonal of degrees
    L=D-A

    eigenvalues,eigenvectors=np.linalg.eig(L)
    # sort and keep smallest nonzero
    index=np.argsort(eigenvalues)[1:dim+1] # 0 index is zero eigenvalue
    return np.real(eigenvectors[:,index]) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:26,代码来源:layout.py

示例4: test_smoke_int

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import spectral_layout [as 别名]
def test_smoke_int(self):
        G = self.Gi
        vpos = nx.random_layout(G)
        vpos = nx.circular_layout(G)
        vpos = nx.planar_layout(G)
        vpos = nx.spring_layout(G)
        vpos = nx.fruchterman_reingold_layout(G)
        vpos = nx.fruchterman_reingold_layout(self.bigG)
        vpos = nx.spectral_layout(G)
        vpos = nx.spectral_layout(G.to_directed())
        vpos = nx.spectral_layout(self.bigG)
        vpos = nx.spectral_layout(self.bigG.to_directed())
        vpos = nx.shell_layout(G)
        if self.scipy is not None:
            vpos = nx.kamada_kawai_layout(G)
            vpos = nx.kamada_kawai_layout(G, dim=1) 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:test_layout.py

示例5: test_empty_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import spectral_layout [as 别名]
def test_empty_graph(self):
        G = nx.empty_graph()
        vpos = nx.random_layout(G, center=(1, 1))
        assert_equal(vpos, {})
        vpos = nx.circular_layout(G, center=(1, 1))
        assert_equal(vpos, {})
        vpos = nx.planar_layout(G, center=(1, 1))
        assert_equal(vpos, {})
        vpos = nx.bipartite_layout(G, G)
        assert_equal(vpos, {})
        vpos = nx.spring_layout(G, center=(1, 1))
        assert_equal(vpos, {})
        vpos = nx.fruchterman_reingold_layout(G, center=(1, 1))
        assert_equal(vpos, {})
        vpos = nx.spectral_layout(G, center=(1, 1))
        assert_equal(vpos, {})
        vpos = nx.shell_layout(G, center=(1, 1))
        assert_equal(vpos, {}) 
开发者ID:holzschu,项目名称:Carnets,代码行数:20,代码来源:test_layout.py

示例6: _spectral

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import spectral_layout [as 别名]
def _spectral(A, dim=2):
    # Input adjacency matrix A
    # Uses dense eigenvalue solver from numpy
    try:
        import numpy as np
    except ImportError:
        msg = "spectral_layout() requires numpy: http://scipy.org/ "
        raise ImportError(msg)
    try:
        nnodes, _ = A.shape
    except AttributeError:
        msg = "spectral() takes an adjacency matrix as input"
        raise nx.NetworkXError(msg)

    # form Laplacian matrix
    # make sure we have an array instead of a matrix
    A = np.asarray(A)
    I = np.identity(nnodes, dtype=A.dtype)
    D = I * np.sum(A, axis=1)  # diagonal of degrees
    L = D - A

    eigenvalues, eigenvectors = np.linalg.eig(L)
    # sort and keep smallest nonzero
    index = np.argsort(eigenvalues)[1:dim + 1]  # 0 index is zero eigenvalue
    return np.real(eigenvectors[:, index]) 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:27,代码来源:layout.py

示例7: plot_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import spectral_layout [as 别名]
def plot_graph(self):
    import matplotlib.pyplot as plt

    pos=networkx.spring_layout(self.G,iterations=2000)
    #pos=networkx.spectral_layout(G)
    #pos = networkx.random_layout(G)
    networkx.draw_networkx_nodes(self.G, pos)
    networkx.draw_networkx_edges(self.G, pos, arrows=True)
    networkx.draw_networkx_labels(self.G, pos)
    plt.show() 
开发者ID:vallettea,项目名称:koala,代码行数:12,代码来源:serializer.py

示例8: plot_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import spectral_layout [as 别名]
def plot_graph(G, filename='prova.png', values=None, colorbar_obj=None):
    
    func_types_dic = {
                'spring' : nx.spring_layout,
                'random' : nx.random_layout,
                'shell' : nx.shell_layout,
                'spectral' : nx.spectral_layout,
                'viz' : graphviz_layout
                }

    print(G.edges())
    print(G.nodes())

    fig = plt.figure(figsize=(10, 10))
    ax = fig.add_subplot(111)

    color_nodes = [values.get(node, 0.2) for node in G.nodes()] 

    pos = func_types_dic[params.plot_type_str](G)

    nodes = nx.draw_networkx_nodes(G, pos, node_color=color_nodes, \
            alpha=.6)#, cmap=plt.get_cmap('brg'))

    nx.draw_networkx_edges(G, pos, width=2.)
    nx.draw_networkx_labels(G, pos, font_color='k', font_weight='10')
    plt.title("|V| = %d, |E| = %d"%(len(G.nodes()), len(G.edges())))
    colorbar_obj.set_array(color_nodes)
    plt.colorbar(colorbar_obj)
    plt.axis('off')
    fig.savefig(filename, format='png')
    plt.close() 
开发者ID:ksanjeevan,项目名称:mapper-tda,代码行数:33,代码来源:em_help.py

示例9: test_smoke_int

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import spectral_layout [as 别名]
def test_smoke_int(self):
        G=self.Gi
        vpos=nx.random_layout(G)
        vpos=nx.circular_layout(G)
        vpos=nx.spring_layout(G)
        vpos=nx.fruchterman_reingold_layout(G)
        vpos=nx.spectral_layout(G)
        vpos=nx.spectral_layout(self.bigG)
        vpos=nx.shell_layout(G) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:11,代码来源:test_layout.py

示例10: test_smoke_string

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import spectral_layout [as 别名]
def test_smoke_string(self):
        G = self.Gs
        vpos = nx.random_layout(G)
        vpos = nx.circular_layout(G)
        vpos = nx.spring_layout(G)
        vpos = nx.fruchterman_reingold_layout(G)
        vpos = nx.spectral_layout(G)
        vpos = nx.shell_layout(G) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:10,代码来源:test_layout.py

示例11: test_empty_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import spectral_layout [as 别名]
def test_empty_graph(self):
        G=nx.Graph()
        vpos = nx.random_layout(G)
        vpos = nx.circular_layout(G)
        vpos = nx.spring_layout(G)
        vpos = nx.fruchterman_reingold_layout(G)
        vpos = nx.shell_layout(G)
        vpos = nx.spectral_layout(G)
        # center arg
        vpos = nx.random_layout(G, scale=2, center=(4,5))
        vpos = nx.circular_layout(G, scale=2, center=(4,5))
        vpos = nx.spring_layout(G, scale=2, center=(4,5))
        vpos = nx.shell_layout(G, scale=2, center=(4,5))
        vpos = nx.spectral_layout(G, scale=2, center=(4,5)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:16,代码来源:test_layout.py

示例12: test_single_node

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import spectral_layout [as 别名]
def test_single_node(self):
        G = nx.Graph()
        G.add_node(0)
        vpos = nx.random_layout(G)
        vpos = nx.circular_layout(G)
        vpos = nx.spring_layout(G)
        vpos = nx.fruchterman_reingold_layout(G)
        vpos = nx.shell_layout(G)
        vpos = nx.spectral_layout(G)
        # center arg
        vpos = nx.random_layout(G, scale=2, center=(4,5))
        vpos = nx.circular_layout(G, scale=2, center=(4,5))
        vpos = nx.spring_layout(G, scale=2, center=(4,5))
        vpos = nx.shell_layout(G, scale=2, center=(4,5))
        vpos = nx.spectral_layout(G, scale=2, center=(4,5)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:17,代码来源:test_layout.py

示例13: test_scale_and_center_arg

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import spectral_layout [as 别名]
def test_scale_and_center_arg(self):
        G = nx.complete_graph(9)
        G.add_node(9)
        vpos = nx.random_layout(G, scale=2, center=(4,5))
        self.check_scale_and_center(vpos, scale=2, center=(4,5))
        vpos = nx.spring_layout(G, scale=2, center=(4,5))
        self.check_scale_and_center(vpos, scale=2, center=(4,5))
        vpos = nx.spectral_layout(G, scale=2, center=(4,5))
        self.check_scale_and_center(vpos, scale=2, center=(4,5))
        # circular can have twice as big length
        vpos = nx.circular_layout(G, scale=2, center=(4,5))
        self.check_scale_and_center(vpos, scale=2*2, center=(4,5))
        vpos = nx.shell_layout(G, scale=2, center=(4,5))
        self.check_scale_and_center(vpos, scale=2*2, center=(4,5))

        # check default center and scale
        vpos = nx.random_layout(G)
        self.check_scale_and_center(vpos, scale=1, center=(0.5,0.5))
        vpos = nx.spring_layout(G)
        self.check_scale_and_center(vpos, scale=1, center=(0.5,0.5))
        vpos = nx.spectral_layout(G)
        self.check_scale_and_center(vpos, scale=1, center=(0.5,0.5))
        vpos = nx.circular_layout(G)
        self.check_scale_and_center(vpos, scale=2, center=(0,0))
        vpos = nx.shell_layout(G)
        self.check_scale_and_center(vpos, scale=2, center=(0,0)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:28,代码来源:test_layout.py

示例14: test_smoke_empty_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import spectral_layout [as 别名]
def test_smoke_empty_graph(self):
        G = []
        vpos = nx.random_layout(G)
        vpos = nx.circular_layout(G)
        vpos = nx.planar_layout(G)
        vpos = nx.spring_layout(G)
        vpos = nx.fruchterman_reingold_layout(G)
        vpos = nx.spectral_layout(G)
        vpos = nx.shell_layout(G)
        vpos = nx.bipartite_layout(G, G)
        if self.scipy is not None:
            vpos = nx.kamada_kawai_layout(G) 
开发者ID:holzschu,项目名称:Carnets,代码行数:14,代码来源:test_layout.py

示例15: test_smoke_string

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import spectral_layout [as 别名]
def test_smoke_string(self):
        G = self.Gs
        vpos = nx.random_layout(G)
        vpos = nx.circular_layout(G)
        vpos = nx.planar_layout(G)
        vpos = nx.spring_layout(G)
        vpos = nx.fruchterman_reingold_layout(G)
        vpos = nx.spectral_layout(G)
        vpos = nx.shell_layout(G)
        if self.scipy is not None:
            vpos = nx.kamada_kawai_layout(G)
            vpos = nx.kamada_kawai_layout(G, dim=1) 
开发者ID:holzschu,项目名称:Carnets,代码行数:14,代码来源:test_layout.py


注:本文中的networkx.spectral_layout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。