qa_adjacency.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:ndmg 作者: neurodata 项目源码 文件源码
def graph2png(infile, outdir, fname=None):
    '''
    infile: input .gpickle or .graphml file
    outdir: path to directory to store output png files
    '''
    # if file is .gpickle, otherwise load .graphml
    try:
        graph = nx.read_gpickle(infile)
    except:
        graph = nx.read_graphml(infile)
    # get numpy array equivalent of adjacency matrix
    g = nx.adj_matrix(graph).todense()
    fig = plt.figure(figsize=(7, 7))
    # plot adjacency matrix
    p = plt.imshow(g, interpolation='None', cmap='jet')
    if fname is None:
        fname = os.path.split(infile)[1].split('.')[0] + '.png'
    save_location = outdir + fname
    plt.savefig(save_location, format='png')
    print(fname + ' done!')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号