Python networkx 模块,info() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用networkx.info()

项目:mrqap-python    作者:lisette-espin    | 项目源码 | 文件源码
def generateGraph(nnodes, edgeprob, directed, pathtosave):
    if os.path.exists(pathtosave):
        matrix = np.loadtxt(pathtosave)
    else:
        shape = (nnodes,nnodes)
        G = nx.fast_gnp_random_graph(n=nnodes, p=edgeprob, directed=directed)
        matrix = nx.adjacency_matrix(G)

        if pathtosave is not None:
            np.savetxt(pathtosave, matrix.toarray(), fmt='%d',)

        print nx.info(G)
        matrix = matrix.toarray()

    return matrix

#######################################################################
# Main
#######################################################################
项目:ride    作者:KyleBenson    | 项目源码 | 文件源码
def draw_overlaid_graphs(original, new_graphs, print_text=False):
    """
    Draws the new_graphs as graphs overlaid on the original topology
    :type new_graphs: list[nx.Graph]
    """
    import matplotlib.pyplot as plt

    layout = nx.spring_layout(original)
    nx.draw_networkx(original, pos=layout)
    # want to overlay edges in different colors and progressively thinner
    # so that we can see what edges are in a tree
    line_colors = 'rbgycm'
    line_width = 2.0 ** (min(len(new_graphs), len(line_colors)) - 1)  # use this for visualising on screen
    # line_width = 3.0 ** (min(len(new_graphs), len(line_colors)) - 1)  # use this for generating diagrams
    for i, g in enumerate(new_graphs):
        if print_text:
            log.info(nx.info(g))
            log.info("edges:", list(g.edges()))
        nx.draw_networkx(g, pos=layout, edge_color=line_colors[i % len(line_colors)], width=line_width)
        # advance to next line width
        line_width /= 1.7  # use this for visualising on screen
        # line_width /= 2.0  # use this for generating diagrams
    plt.show()
项目:graynet    作者:raamana    | 项目源码 | 文件源码
def add_nodal_positions(graph, centroids):
    "Adds the x, y, z attributes to each node in graph."

    # adding position info to nodes (for visualization later)
    for roi in centroids:
        graph.node[roi]['x'] = float(centroids[roi][0])
        graph.node[roi]['y'] = float(centroids[roi][1])
        graph.node[roi]['z'] = float(centroids[roi][2])

    return
项目:graynet    作者:raamana    | 项目源码 | 文件源码
def save_summary_graph(graph, out_dir, subject,
                       str_suffix=None,
                       summary_descr='summary'):
    "Saves the features to disk."

    if out_dir is not None:
        # get outpath returned from hiwenet, based on dist name and all other parameters
        # choose out_dir name  based on dist name and all other parameters
        out_subject_dir = pjoin(out_dir, subject)
        if not pexists(out_subject_dir):
            os.mkdir(out_subject_dir)

        if str_suffix is not None:
            out_file_name = '{}_{}_multigraph_graynet.graphml'.format(str_suffix,summary_descr)
        else:
            out_file_name = '_{}_multigraph_graynet.graphml'.format(summary_descr)

        out_weights_path = pjoin(out_subject_dir, out_file_name)

        try:
            nx.info(graph)
            nx.write_graphml(graph, out_weights_path, encoding='utf-8')
            print('\nSaved the summary multi-graph to \n{}'.format(out_weights_path))
        except:
            print('\nUnable to save summary multi-graph to \n{}'.format(out_weights_path))
            traceback.print_exc()

    return
项目:graynet    作者:raamana    | 项目源码 | 文件源码
def save_graph(graph_nx, out_dir, subject, str_suffix=None):
    "Saves the features to disk."

    if out_dir is not None:
        # get outpath returned from hiwenet, based on dist name and all other parameters
        # choose out_dir name  based on dist name and all other parameters
        out_subject_dir = pjoin(out_dir, subject)
        if not pexists(out_subject_dir):
            os.mkdir(out_subject_dir)

        if str_suffix is not None:
            out_file_name = '{}_graynet.graphml'.format(str_suffix)
        else:
            out_file_name = 'graynet.graphml'

        out_weights_path = pjoin(out_subject_dir, out_file_name)

        try:
            nx.info(graph_nx)
            nx.write_graphml(graph_nx, out_weights_path, encoding='utf-8')
            print('\nSaved the graph to \n{}'.format(out_weights_path))
        except:
            print('\nUnable to save graph to \n{}'.format(out_weights_path))
            traceback.print_exc()

    return
项目:ndmg    作者:neurodata    | 项目源码 | 文件源码
def summary(self):
        """
        User friendly wrapping and display of graph properties
        """
        print("\n Graph Summary:")
        print(nx.info(self.g))
        pass
项目:ride    作者:KyleBenson    | 项目源码 | 文件源码
def get_info(self):
        return nx.info(self.topo)