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


Python json_graph.node_link_data方法代码示例

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


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

示例1: __init__

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import node_link_data [as 别名]
def __init__(self, G, pos, ax,
                 gravity=1,
                 link_distance=20,
                 charge=-30,
                 node_size=5,
                 link_strength=1,
                 friction=0.9,
                 draggable=True):

        if pos is None:
            pass

        self.dict_ = {"type": "networkxd3forcelayout",
                      "graph": node_link_data(G),
                      "ax_id": mpld3.utils.get_id(ax),
                      "gravity": gravity,
                      "charge": charge,
                      "friction": friction,
                      "link_distance": link_distance,
                      "link_strength": link_strength,
                      "draggable": draggable,
                      "nominal_radius": node_size} 
开发者ID:power-system-simulation-toolbox,项目名称:psst,代码行数:24,代码来源:plotmpld3.py

示例2: compute_label_smoothness

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import node_link_data [as 别名]
def compute_label_smoothness(path, rate=0.):
    G_org = json_graph.node_link_graph(json.load(open(path+'-G.json')))
    # G_org = remove_unlabeled(G_org)
    if nx.is_directed(G_org):
        G_org = G_org.to_undirected()
    class_map = json.load(open(path+'-class_map.json'))
    for k, v in class_map.items():
        if type(v) != list:
            class_map = convert_list(class_map)
        break
    labels = convert_ndarray(class_map)
    labels = np.squeeze(label_to_vector(labels))

    # smooth
    G_org = label_broadcast(G_org, labels, rate)
    with open(path+'-G_'+str(rate)+'.json', 'w') as f:
        f.write(json.dumps(json_graph.node_link_data(G_org)))

    edge_num = G_org.number_of_edges()
    G = pygsp.graphs.Graph(nx.adjacency_matrix(G_org))
    smoothness = 0
    for src, dst in G_org.edges():
        if labels[src] != labels[dst]:
            smoothness += 1
    print('The smoothness is: ', 2*smoothness/edge_num) 
开发者ID:yifan-h,项目名称:CS-GNN,代码行数:27,代码来源:smoothness.py

示例3: serialize

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import node_link_data [as 别名]
def serialize(g: nx.MultiDiGraph) -> Dict:
        """
        Convert networkx.MultiDiGraph as a dictionary.

        Parameters
        ----------
        g: networkx.MultiDiGraph
            Graph to convert as a dictionary

        Returns
        -------
        dict
            A dictionary

        """
        data = json_graph.node_link_data(g)
        return data 
开发者ID:NCATS-Tangerine,项目名称:kgx,代码行数:19,代码来源:transformer.py

示例4: save_json_tree

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import node_link_data [as 别名]
def save_json_tree(filepath, tree):
        """
        Transform inferred phylogeny to JSON object and save it to a file
        :param filepath: path to the output file
        :param tree: reconstructed phylogeny given as networkx DiGraph object
        """

        # create simplified JSON tree
        out_ids = dict()
        out_tree = nx.DiGraph()
        for out_id, node in enumerate(tree.nodes()):
            out_ids[node] = out_id
            out_tree.add_node(out_id, name=tree.node[node]['name'])

        for u, v in tree.edges():
            out_tree.add_edge(out_ids[u], out_ids[v], value=len(tree.edge[u][v]['muts']))

        # create json output from reconstructed phylogeny
        json_data = json_graph.node_link_data(out_tree)

        # json object to output file
        with open(filepath, 'w') as json_file:
            json.dump(json_data, json_file, indent=4)
            logger.info('Create JSON file from reconstructed phylogeny: {}.'.format(filepath)) 
开发者ID:johannesreiter,项目名称:treeomics,代码行数:26,代码来源:phylogeny_utils.py

示例5: serialize_graph

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import node_link_data [as 别名]
def serialize_graph(graph):
    """Make string."""
    json_data = json_graph.node_link_data(graph)
    serial_data = json.dumps(json_data,
                             separators=(',', ':'),
                             indent=4,
                             cls=SetEncoder)
    return serial_data 
开发者ID:fabriziocosta,项目名称:EDeN,代码行数:10,代码来源:__init__.py

示例6: node_link_data_to_eden

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import node_link_data [as 别名]
def node_link_data_to_eden(input=None, options=dict()):
    """
    Takes a string list in the serialised node_link_data JSON format and yields networkx graphs.

    Parameters
    ----------
    input : string
        A pointer to the data source.

    """

    return _node_link_data_to_eden(util.read(input)) 
开发者ID:fabriziocosta,项目名称:EDeN,代码行数:14,代码来源:node_link_data.py

示例7: _node_link_data_to_eden

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import node_link_data [as 别名]
def _node_link_data_to_eden(serialized_list):
    """Takes a string list in the serialised node_link_data JSON format and yields networkx graphs."""
    for serial_data in serialized_list:
        py_obj = json.loads(serial_data)
        graph = json_graph.node_link_graph(py_obj)
        yield graph 
开发者ID:fabriziocosta,项目名称:EDeN,代码行数:8,代码来源:node_link_data.py

示例8: eden_to_node_link_data

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import node_link_data [as 别名]
def eden_to_node_link_data(graph_list):
    """Takes a list of networkx graphs and yields serialised node_link_data JSON strings."""
    for G in graph_list:
        json_data = json_graph.node_link_data(G)
        serial_data = json.dumps(json_data)
        yield serial_data 
开发者ID:fabriziocosta,项目名称:EDeN,代码行数:8,代码来源:node_link_data.py

示例9: eden_to_node_link_file

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import node_link_data [as 别名]
def eden_to_node_link_file(graph_list, fname):
    """Takes a list of networkx graphs and writes a serialised node_link_data JSON file."""
    with open(fname, 'w') as f:
        serials = eden_to_node_link_data(graph_list)
        for serial in serials:
            f.write('%s\n' % serial) 
开发者ID:fabriziocosta,项目名称:EDeN,代码行数:8,代码来源:node_link_data.py

示例10: get_bundle

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import node_link_data [as 别名]
def get_bundle(self, user):
        graph = self.build_graph(user)
        return json_graph.node_link_data(graph) 
开发者ID:arguman,项目名称:arguman.org,代码行数:5,代码来源:views.py

示例11: tryout_web_graphs

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import node_link_data [as 别名]
def tryout_web_graphs(self, infr):
    """
    https://plot.ly/python/

    http://bokeh.pydata.org/en/latest/

    pip install bokeh

    Notes:
        http://www.coppelia.io/2014/07/an-a-to-z-of-extra-features-for-the-d3-force-layout/
        http://andrewmellor.co.uk/blog/articles/2014/12/14/d3-networks/
        pip install plotly  # eww need to sign up and get a key
        http://igraph.org/
    import mpld3
    mpld3.save_html(fig, open('fig.html', 'w'))
    mpld3.save_json(fig, open('fig.json', 'w'))
    fig = pt.gcf()
    """
    #import plottool_ibeis as pt
    # http://andrewmellor.co.uk/blog/articles/2014/12/14/d3-networks/
    from networkx.readwrite import json_graph

    G = infr.graph
    data = json_graph.node_link_data(G)
    json_text = ut.to_json(data, pretty=True)
    ut.writeto('graph.json', json_text)
    ut.editfile('graph.json')

    ut.startfile('d3_example.html')
    # d3_location = ut.grab_zipped_url('https://github.com/d3/d3/releases/download/v3.5.17/d3.zip')
    # python -m SimpleHTTPServer 8000 
开发者ID:Erotemic,项目名称:ibeis,代码行数:33,代码来源:viz_graph.py

示例12: save_js_arc

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import node_link_data [as 别名]
def save_js_arc(reduced_CC_graph, channels_hash, output_directory, output_file_name):
    """
        Saves the nx_graph as a js file with variable name communities, it is used in index.html to generate the arc graph

    Args:
        nx_graph: a networkx graph, here it is the reduced community community graph
        channels_hash(dict): list of channel names
        output_drectory(str): location where to save the file
        output_file_name(str): name of the file to be saved
        
    Returns:
       null
        
    """
    check_if_dir_exists(output_directory) #create output directory if doesn't exist
    copy2("./lib/protovis/" + "arc_graph.html", output_directory) #copy required files to output_directory
    copy2("./lib/protovis/" + "ex.css", output_directory)
    copy2("./lib/protovis/" + "protovis-r3.2.js", output_directory)
    jsondict = json_graph.node_link_data(reduced_CC_graph)
    max_weight_val = max(item['weight'] for item in jsondict['links'])
    # the key names in the jsondict_top_channels are kept as the following so that index.html can render it
    jsondict_top_channels = {}
    jsondict_top_channels['nodes'] = [{'nodeName':channels_hash[int(node['id']) - config.STARTING_HASH_CHANNEL]} for node in jsondict['nodes']]
    jsondict_top_channels['links'] = [{'source': link['source'], 'target': link['target'],\
                                    'value': int(link['weight'] * config.EXPANSION_PARAMETER / float(max_weight_val))} for link in jsondict['links']]

    with open(output_directory + output_file_name, 'w') as f:
        f.write("var communities =")
        json.dump(jsondict_top_channels, f) 
开发者ID:prasadtalasila,项目名称:IRCLogParser,代码行数:31,代码来源:saver.py

示例13: json_G

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import node_link_data [as 别名]
def json_G(self, G):
        return json_graph.node_link_data(G) 
开发者ID:fabioserpa,项目名称:CNPJ-full,代码行数:4,代码来源:rede_cnpj.py

示例14: to_dict

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import node_link_data [as 别名]
def to_dict(self):
        return json_graph.node_link_data(self.graph) 
开发者ID:pudo-attic,项目名称:jsonmapping,代码行数:4,代码来源:network.py

示例15: json_output_graph

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import node_link_data [as 别名]
def json_output_graph(self, **kwargs):
        """supports both 1.10<=networkx<2.0 and networx>=2.0 by returning the

        same json output regardless networx version

        :return: graph in json format
        """

        # TODO(annarez): when we decide to support networkx 2.0 with
        # versioning of Vitrage, we can move part of the logic to vitrageclient
        node_link_data = json_graph.node_link_data(self._g)
        node_link_data.update(kwargs)

        vitrage_id_to_index = dict()

        for index, node in enumerate(node_link_data['nodes']):
            vitrage_id_to_index[node[VProps.VITRAGE_ID]] = index
            if VProps.ID in self._g.nodes[node[VProps.ID]]:
                node[VProps.ID] = self._g.nodes[node[VProps.ID]][VProps.ID]
                node[VProps.GRAPH_INDEX] = index

        vers = nx.__version__
        if vers >= '2.0':
            for i in range(len(node_link_data['links'])):
                node_link_data['links'][i]['source'] = vitrage_id_to_index[
                    node_link_data['links'][i]['source']]
                node_link_data['links'][i]['target'] = vitrage_id_to_index[
                    node_link_data['links'][i]['target']]

        if kwargs.get('raw', False):
            return node_link_data
        else:
            return json.dumps(node_link_data) 
开发者ID:openstack,项目名称:vitrage,代码行数:35,代码来源:networkx_graph.py


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